Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for an option to leave import paths alone. #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ unlinked QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw /home/user/go/src/github
Name: "a,all",
Usage: "Remove all existing symlinks and reinstate the gx packages. Use with -r.",
},
cli.BoolFlag{
Name: "n,no-rewrite",
Usage: "Re-write or un-rewrite import paths",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Don't rewrite or unrewrite import paths"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just "Dont modify import paths" ?

},
},
Action: func(c *cli.Context) error {
remove := c.Bool("remove")
all := c.Bool("all")
noRewrite := c.Bool("no-rewrite")

hashes := c.Args()[:]
if len(hashes) == 0 {
Expand All @@ -81,13 +86,13 @@ unlinked QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw /home/user/go/src/github

for _, hash := range hashes {
if remove {
target, err := unlinkPackage(hash)
target, err := unlinkPackage(hash, noRewrite)
if err != nil {
return err
}
fmt.Printf("unlinked %s %s\n", hash, target)
} else {
target, err := linkPackage(hash)
target, err := linkPackage(hash, noRewrite)
if err != nil {
return err
}
Expand Down Expand Up @@ -138,7 +143,7 @@ func listLinkedPackages() ([][]string, error) {
// rm -rf $GOPATH/src/gx/ipfs/$hash/$pkgname
// ln -s $GOPATH/src/$dvcsimport $GOPATH/src/gx/ipfs/$hash/$pkgname
// cd $GOPATH/src/$dvcsimport && gx install && gx-go rewrite
func linkPackage(hash string) (string, error) {
func linkPackage(hash string, noRewrite bool) (string, error) {
srcdir, err := gx.InstallPath("go", "", true)
if err != nil {
return "", err
Expand Down Expand Up @@ -192,6 +197,10 @@ func linkPackage(hash string) (string, error) {
return "", fmt.Errorf("error during gx install: %s", err)
}

if noRewrite {
return target, nil
}

rwcmd := exec.Command("gx-go", "rw")
rwcmd.Dir = target
rwcmd.Stdout = nil
Expand All @@ -205,7 +214,7 @@ func linkPackage(hash string) (string, error) {

// rm -rf $GOPATH/src/gx/ipfs/$hash
// gx get $hash
func unlinkPackage(hash string) (string, error) {
func unlinkPackage(hash string, noRewrite bool) (string, error) {
srcdir, err := gx.InstallPath("go", "", true)
if err != nil {
return "", err
Expand Down Expand Up @@ -233,6 +242,10 @@ func unlinkPackage(hash string) (string, error) {
dvcsimport := GxDvcsImport(&pkg)
target := filepath.Join(srcdir, dvcsimport)

if noRewrite {
return target, nil
}

uwcmd := exec.Command("gx-go", "uw")
uwcmd.Dir = target
uwcmd.Stdout = nil
Expand Down