Skip to content

Commit

Permalink
run: add file path (-p) option to list
Browse files Browse the repository at this point in the history
This commit adds a `-p` option to the `list` sub-command that causes
govendor to print the file path to the package instead of the Go import
path.
  • Loading branch information
moorereason committed Sep 16, 2016
1 parent efaf6ab commit 58f2edf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion context/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (ctx *Context) updateStatusCache() error {

li := StatusItem{
Status: pkg.Status,
Pkg: &pkgspec.Pkg{Path: pkg.Path, IncludeTree: pkg.IncludeTree, Origin: origin, Version: version},
Pkg: &pkgspec.Pkg{Path: pkg.Path, IncludeTree: pkg.IncludeTree, Origin: origin, Version: version, FilePath: pkg.Dir},
Local: pkg.Local,
VersionExact: versionExact,
ImportedBy: make([]*Package, 0, len(pkg.referenced)),
Expand Down
2 changes: 2 additions & 0 deletions help/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ var helpList = `govendor list [options] ( +status or import-path-filter )
List all dependencies and packages in folder tree.
Options:
-v verbose listing, show dependencies of each package
-p show file path to package instead of import path
-no-status do not prefix status to list, package names only
Examples:
$ govendor list -no-status +local
$ govendor list -p -no-status +local
$ govendor list +vend,prog +local,program
$ govendor list +local,^prog
`
Expand Down
1 change: 1 addition & 0 deletions pkgspec/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "bytes"

type Pkg struct {
Path string
FilePath string
Origin string
IncludeTree bool
MatchTree bool
Expand Down
12 changes: 10 additions & 2 deletions run/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (r *runner) List(w io.Writer, subCmdArgs []string) (help.HelpMessage, error
listFlags := flag.NewFlagSet("list", flag.ContinueOnError)
listFlags.SetOutput(nullWriter{})
verbose := listFlags.Bool("v", false, "verbose")
asFilePath := listFlags.Bool("p", false, "show file path to package instead of import path")
noStatus := listFlags.Bool("no-status", false, "do not show the status")
err := listFlags.Parse(subCmdArgs)
if err != nil {
Expand Down Expand Up @@ -105,10 +106,17 @@ func (r *runner) List(w io.Writer, subCmdArgs []string) (help.HelpMessage, error
continue
}

var path string
if *asFilePath {
path = item.Pkg.FilePath
} else {
path = item.Pkg.Path
}

if item.Local == item.Pkg.Path {
fmt.Fprintf(tw, formatSame, item.Status, item.Pkg.Path, item.Pkg.Version, item.VersionExact)
fmt.Fprintf(tw, formatSame, item.Status, path, item.Pkg.Version, item.VersionExact)
} else {
fmt.Fprintf(tw, formatDifferent, item.Status, item.Pkg.Path, strings.TrimPrefix(item.Local, ctx.RootImportPath), item.Pkg.Version, item.VersionExact)
fmt.Fprintf(tw, formatDifferent, item.Status, path, strings.TrimPrefix(item.Local, ctx.RootImportPath), item.Pkg.Version, item.VersionExact)
}
if *verbose {
for i, imp := range item.ImportedBy {
Expand Down

0 comments on commit 58f2edf

Please sign in to comment.