-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
83 lines (74 loc) · 1.72 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
package main
import (
_ "embed"
"fmt"
"os"
"path/filepath"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
"github.com/boyvinall/dirtygit/scanner"
"github.com/boyvinall/dirtygit/ui"
)
func getDefaultConfigPath() string {
home, err := homedir.Dir()
_ = err // ignore
return filepath.Join(home, ".dirtygit.yml")
}
//go:embed .dirtygit.yml
var defaultConfig string
func main() {
app := cli.NewApp()
app.Name = "dirtygit"
app.Usage = "Finds git repos in need of commitment"
app.EnableBashCompletion = true
app.CommandNotFound = func(c *cli.Context, cmd string) {
fmt.Printf("ERROR: Unknown command '%s'\n", cmd)
}
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Location of config file",
Value: getDefaultConfigPath(),
},
&cli.BoolFlag{
Name: "debug",
Usage: "show debug output instead of UI",
},
}
app.Action = func(c *cli.Context) error {
config, err := scanner.ParseConfigFile(c.String("config"), defaultConfig)
if err != nil {
return err
}
if c.Args().Len() > 0 {
config.ScanDirs.Include = c.Args().Slice()
}
for i := range config.ScanDirs.Include {
config.ScanDirs.Include[i] = os.ExpandEnv(config.ScanDirs.Include[i])
}
for i := range config.ScanDirs.Exclude {
config.ScanDirs.Exclude[i] = os.ExpandEnv(config.ScanDirs.Exclude[i])
}
if c.Bool("debug") {
var mgs scanner.MultiGitStatus
mgs, err = scanner.Scan(config)
if err != nil {
panic(err)
}
for r, st := range mgs {
fmt.Printf("%-40s %v\n", r, st.ScanTime)
}
return nil
}
err = ui.Run(config)
if err != nil {
return err
}
return nil
}
err := app.Run(os.Args)
if err != nil {
fmt.Printf("%+v\n", err)
}
}