Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
Permalink
v0.4.4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
53 lines (46 sloc) 1.34 KB
package main
import (
"flag"
"fmt"
"html/template"
"os"
"text/tabwriter"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
"github.com/constabulary/gb/internal/vendor"
"github.com/pkg/errors"
)
var format string
var cmdList = &cmd.Command{
Name: "list",
UsageLine: "list [-f format]",
Short: "lists dependencies, one per line",
Long: `gb vendor list formats lists the contents of the manifest file.
The output
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(ctx *gb.Context, args []string) error {
m, err := vendor.ReadManifest(manifestFile(ctx))
if err != nil {
return errors.Wrap(err, "could not load manifest")
}
tmpl, err := template.New("list").Parse(format)
if err != nil {
return errors.Wrapf(err, "unable to parse template %q", format)
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 1, ' ', 0)
for _, dep := range m.Dependencies {
if err := tmpl.Execute(w, dep); err != nil {
return errors.Wrap(err, "unable to execute template")
}
fmt.Fprintln(w)
}
return w.Flush()
},
AddFlags: func(fs *flag.FlagSet) {
fs.StringVar(&format, "f", "{{.Importpath}}\t{{.Repository}}{{.Path}}\t{{.Branch}}\t{{.Revision}}", "format template")
},
}