Skip to content

Commit

Permalink
add helper command to show dvcs deps
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Apr 26, 2016
1 parent 1fd3e84 commit 9d167af
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
6 changes: 3 additions & 3 deletions importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (i *Importer) GxPublishGoPackage(imppath string) (*gx.Dependency, error) {
pkg.Dependencies = nil

// recurse!
depsToVendor, err := i.depsToVendorForPackage(imppath)
depsToVendor, err := i.DepsToVendorForPackage(imppath)
if err != nil {
return nil, fmt.Errorf("error fetching deps for %s: %s", imppath, err)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (i *Importer) GxPublishGoPackage(imppath string) (*gx.Dependency, error) {
return dep, nil
}

func (i *Importer) depsToVendorForPackage(path string) ([]string, error) {
func (i *Importer) DepsToVendorForPackage(path string) ([]string, error) {
rdeps := make(map[string]struct{})

gopkg, err := i.bctx.Import(path, "", 0)
Expand Down Expand Up @@ -265,7 +265,7 @@ func (i *Importer) depsToVendorForPackage(path string) ([]string, error) {
continue
}

out, err := i.depsToVendorForPackage(filepath.Join(path, e.Name()))
out, err := i.DepsToVendorForPackage(filepath.Join(path, e.Name()))
if err != nil {
return nil, err
}
Expand Down
77 changes: 56 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,6 @@ for each.`,
},
}

var PathCommand = cli.Command{
Name: "path",
Usage: "prints the import path of the current package within GOPATH",
Action: func(c *cli.Context) {
gopath, err := getGoPath()
if err != nil {
Fatal("GOPATH not set, cannot derive import path")
}

srcdir := path.Join(gopath, "src")
srcdir += "/"

if !strings.HasPrefix(cwd, srcdir) {
Fatal("package not within GOPATH/src")
}

rel := cwd[len(srcdir):]
fmt.Println(rel)
},
}

var RewriteCommand = cli.Command{
Name: "rewrite",
Usage: "temporary hack to evade causality",
Expand Down Expand Up @@ -284,6 +263,31 @@ for each.`,
},
}

var DvcsDepsCommand = cli.Command{
Name: "dvcs-deps",
Usage: "display dvcs deps that arent tracked in gx",
Action: func(c *cli.Context) {
i, err := NewImporter(false, os.Getenv("GOPATH"), nil)
if err != nil {
Fatal(err)
}

relp, err := getImportPath(cwd)
if err != nil {
Fatal(err)
}

deps, err := i.DepsToVendorForPackage(relp)
if err != nil {
Fatal(err)
}

for _, d := range deps {
fmt.Println(d)
}
},
}

var HookCommand = cli.Command{
Name: "hook",
Usage: "go specific hooks to be called by the gx tool",
Expand All @@ -305,11 +309,42 @@ for each.`,
PathCommand,
RewriteCommand,
UpdateCommand,
DvcsDepsCommand,
}

app.Run(os.Args)
}

func getImportPath(pkgpath string) (string, error) {
gopath, err := getGoPath()
if err != nil {
return "", fmt.Errorf("GOPATH not set, cannot derive import path")
}

srcdir := path.Join(gopath, "src")
srcdir += "/"

if !strings.HasPrefix(cwd, srcdir) {
return "", fmt.Errorf("package not within GOPATH/src")
}

rel := cwd[len(srcdir):]
return rel, nil
}

var PathCommand = cli.Command{
Name: "path",
Usage: "prints the import path of the current package within GOPATH",
Action: func(c *cli.Context) {
rel, err := getImportPath(cwd)
if err != nil {
Fatal(err)
}

fmt.Println(rel)
},
}

func prompt(text, def string) (string, error) {
scan := bufio.NewScanner(os.Stdin)
fmt.Printf("%s (default: '%s') ", text, def)
Expand Down

0 comments on commit 9d167af

Please sign in to comment.