forked from FiloSottile/gvt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
52 lines (45 loc) · 1.22 KB
/
list.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
package main
import (
"flag"
"fmt"
"html/template"
"os"
"text/tabwriter"
"github.com/nota/gvt/gbvendor"
)
var (
format string
)
func addListFlags(fs *flag.FlagSet) {
fs.StringVar(&format, "f", "{{.Importpath}}\t{{.Repository}}{{.Path}}\t{{.Branch}}\t{{.Revision}}", "format template")
}
var cmdList = &Command{
Name: "list",
UsageLine: "list [-f format]",
Short: "list dependencies one per line",
Long: `list formats the contents of the manifest file.
Flags:
-f
controls the template used for printing each manifest entry. If not supplied
the default value is "{{.Importpath}}\t{{.Repository}}{{.Path}}\t{{.Branch}}\t{{.Revision}}"
`,
Run: func(args []string) error {
m, err := vendor.ReadManifest(manifestFile)
if err != nil {
return fmt.Errorf("could not load manifest: %v", err)
}
tmpl, err := template.New("list").Parse(format)
if err != nil {
return fmt.Errorf("unable to parse template %q: %v", format, err)
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 1, ' ', 0)
for _, dep := range m.Dependencies {
if err := tmpl.Execute(w, dep); err != nil {
return fmt.Errorf("unable to execute template: %v", err)
}
fmt.Fprintln(w)
}
return w.Flush()
},
AddFlags: addListFlags,
}