forked from brianm/gov
/
main.go
75 lines (66 loc) · 1.49 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
package main
import (
"fmt"
"github.com/brianm/gov/vcs"
"github.com/codegangsta/cli"
"log"
"os"
"path/filepath"
)
func main() {
app := cli.NewApp()
app.Usage = "manage golang build dependencies"
app.EnableBashCompletion = true
app.Version = "0.0.1"
app.Commands = []cli.Command{
{
Name: "report",
ShortName: "r",
Usage: "Report on repos used",
Action: report,
},
{
Name: "bash-autocomplete",
Usage: "Use as 'eval \"$(gov bash-autocomplete)\"' to set up bash autocompletion",
Action: autocomplete,
},
}
app.Run(os.Args)
}
func autocomplete(*cli.Context) {
fmt.Printf("%s", `
_gov_bash_autocomplete() {
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$( ${COMP_WORDS[@]:0:COMP_CWORD} --generate-bash-completion )
# add -f to compgen to get filenames as well
COMPREPLY=( $(compgen -f -W "${opts}" -- ${cur}) )
return 0
}
complete -F _gov_bash_autocomplete gov
`)
}
func report(ctx *cli.Context) {
var path string
var err error
if len(ctx.Args()) < 1 {
path, err = os.Getwd()
if err != nil {
log.Fatalf("Unable to get current directory: %s", err)
}
} else {
path = ctx.Args()[0]
}
rs, err := vcs.FindRepos(path)
if err != nil {
log.Fatalf("error finding repos: %s", err)
panic(err)
}
for _, r := range rs {
if filepath.Clean(path) != filepath.Clean(r.Root()) {
fmt.Printf("%s\t%t\t%v\n", r.Rev(), r.IsClean(), r.Root())
}
}
}