-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (84 loc) · 1.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
gologging "github.com/sigmonsays/go-logging"
)
// These variables are populated by goreleaser when the binary is built.
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
ctx := &Context{}
link := &Link{ctx}
unlink := &Unlink{ctx}
status := &Status{ctx}
clean := &Clean{ctx}
app := &cli.App{
Name: "dotbot",
Usage: "manage dot files",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "loglevel",
Aliases: []string{"l"},
Value: "info",
Usage: "set log level",
},
&cli.StringSliceFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "config file",
},
},
Before: func(c *cli.Context) error {
loglevel := c.String("loglevel")
if loglevel != "" {
gologging.SetLogLevel(loglevel)
}
ctx.configs = c.StringSlice("config")
return nil
},
}
ctx.app = app
ctx.addCommand(&cli.Command{
Name: "link",
Aliases: []string{"l"},
Usage: "create symlinks",
Action: link.Run,
Flags: link.Flags(),
})
ctx.addCommand(&cli.Command{
Name: "unlink",
Aliases: []string{"u"},
Usage: "remove symlinks",
Action: unlink.Run,
Flags: unlink.Flags(),
})
ctx.addCommand(&cli.Command{
Name: "status",
Aliases: []string{"s"},
Usage: "print status table",
Action: status.Run,
Flags: status.Flags(),
})
ctx.addCommand(&cli.Command{
Name: "clean",
Usage: "show unreferenced files",
Action: clean.Run,
Flags: clean.Flags(),
})
ctx.addCommand(&cli.Command{
Name: "version",
Usage: "print version",
Action: func(c *cli.Context) error {
fmt.Printf("version %s\n", version)
fmt.Printf("commit %s\n", commit)
fmt.Printf("date %s\n", date)
return nil
},
})
app.Run(os.Args)
}