Improve: use list command to resolve relative import path#40
Open
leventeliu wants to merge 1 commit intokisielk:masterfrom
Open
Improve: use list command to resolve relative import path#40leventeliu wants to merge 1 commit intokisielk:masterfrom
leventeliu wants to merge 1 commit intokisielk:masterfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this change?
With a very simple repository for demonstration:
git clone https://github.com/leventeliu/godepgraph-demo.git cd godepgraph-demoInitially, when I was trying to get dep-graph inside a go module (given filter
-o <prefix>) with a relative import path syntax,godepgraphgave an empty result:$ godepgraph -o github.com/leventeliu ./cmd/nop digraph godep { splines=ortho nodesep=0.4 ranksep=0.8 node [shape="box",style="rounded,filled"] edge [arrowsize="0.5"] }After some code reading, I found the correct way to do it cloud be:
$ godepgraph -o .,github.com/leventeliu ./cmd/nop digraph godep { splines=ortho nodesep=0.4 ranksep=0.8 node [shape="box",style="rounded,filled"] edge [arrowsize="0.5"] "./cmd/nop" [label="./cmd/nop" color="paleturquoise" URL="https://godoc.org/./cmd/nop" target="_blank"]; "./cmd/nop" -> "github.com/leventeliu/godepgraph-demo/a"; "./cmd/nop" -> "github.com/leventeliu/godepgraph-demo/b"; "github.com/leventeliu/godepgraph-demo/a" [label="github.com/leventeliu/godepgraph-demo/a" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/a" target="_blank"]; "github.com/leventeliu/godepgraph-demo/b" [label="github.com/leventeliu/godepgraph-demo/b" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/b" target="_blank"]; }But it's weird, isn't it? The problem here is that the relative path
./cmd/nopcould (and should) be resolved as a full package pathgithub.com/leventeliu/godepgraph-demo/cmd/nop, which will not be ignored by the filter-o github.com/leventeliu.And after I tried the
listcommand:I thought this is the proper way to solve the problem.
List command is implemented by an internal package, which will be tricky to call directly. Alternatively, I use an
os/exec.Commandto callgo listand pass the parent environment to the command (any better idea?)Now it works well:
$ godepgraph -o github.com/leventeliu ./cmd/nop digraph godep { splines=ortho nodesep=0.4 ranksep=0.8 node [shape="box",style="rounded,filled"] edge [arrowsize="0.5"] "github.com/leventeliu/godepgraph-demo/a" [label="github.com/leventeliu/godepgraph-demo/a" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/a" target="_blank"]; "github.com/leventeliu/godepgraph-demo/b" [label="github.com/leventeliu/godepgraph-demo/b" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/b" target="_blank"]; "github.com/leventeliu/godepgraph-demo/cmd/nop" [label="github.com/leventeliu/godepgraph-demo/cmd/nop" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/cmd/nop" target="_blank"]; "github.com/leventeliu/godepgraph-demo/cmd/nop" -> "github.com/leventeliu/godepgraph-demo/a"; "github.com/leventeliu/godepgraph-demo/cmd/nop" -> "github.com/leventeliu/godepgraph-demo/b"; }This improvement applies to the case when you are working with "GOPATH mode", instead of go module, too.
Also, this implies a special pattern
/...will be supported:$ godepgraph -o github.com/leventeliu ./... digraph godep { splines=ortho nodesep=0.4 ranksep=0.8 node [shape="box",style="rounded,filled"] edge [arrowsize="0.5"] "github.com/leventeliu/godepgraph-demo/a" [label="github.com/leventeliu/godepgraph-demo/a" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/a" target="_blank"]; "github.com/leventeliu/godepgraph-demo/b" [label="github.com/leventeliu/godepgraph-demo/b" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/b" target="_blank"]; "github.com/leventeliu/godepgraph-demo/cmd/nop" [label="github.com/leventeliu/godepgraph-demo/cmd/nop" color="paleturquoise" URL="https://godoc.org/github.com/leventeliu/godepgraph-demo/cmd/nop" target="_blank"]; "github.com/leventeliu/godepgraph-demo/cmd/nop" -> "github.com/leventeliu/godepgraph-demo/a"; "github.com/leventeliu/godepgraph-demo/cmd/nop" -> "github.com/leventeliu/godepgraph-demo/b"; }