This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
Permalink
Cannot retrieve contributors at this time
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?
gb/cmd/gb-vendor/list.go
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (46 sloc)
1.34 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}, | |
} |