I'll use a concrete example. Substitute with your own. 

GOPACKAGE=github.com/mkideal/cli
{ echo "digraph G {"; go list -f '{{ range .Imports }}{{printf "\t%q -> 
%q;\n" $.ImportPath .}}{{end}}' $(go list -f '{{join .Deps " "}}' 
$GOPACKAGE) $GOPACKAGE | grep '/.*" -> ".*/'; echo "}"; } | dot -Tsvg 
-o /tmp/cli.svg

BTW, 

instead of piping the result to dot, I redirect it to /tmp/go.dot, then 
quickly view it with `dotty /tmp/go.dot`.


HTH

On Friday, September 2, 2016 at 5:16:44 PM UTC-4, Davis Ford wrote:
>
> Daniel, fwiw I couldn't get govendor list to work in my environment.
>
> Sam, thanks a lot of that snippet.  I also had some trouble running that, 
> but I was able to reverse engineer the important parts out to generate a 
> one-liner that worked for me.
>
> go list -f '{{ range .Imports }}{{printf "\t%q -> %q;\n" $.ImportPath 
> .}}{{end}}' $(go list -f '{{join .Deps " "}}' YOURPACKAGE) YOURPACKAGE
>
> When I tried the script as is (found a similar script here 
> <https://github.com/NeoHuang/scripts/blob/master/getGoDepends.sh>), it 
> errors out with 
>
> template: main:1: unexpected "\\" in operand
>
> If you know a quick resolution to that, I'd love to get it working with 
> digraph and graphviz, as well.
>
>
> On Fri, Sep 2, 2016 at 2:51 PM, Sam Whited <s...@samwhited.com 
> <javascript:>> wrote:
>
>> On Fri, Sep 2, 2016 at 1:20 PM, Davis Ford <davi...@gmail.com 
>> <javascript:>> wrote:
>> > Does anyone know of a tool that can analyze dependencies and print a 
>> graph,
>> > specifically as it relates to golang vendor'd libraries.  I'm using 1.7 
>> and
>> > most tools don't seem to be able to produce results on a project that is
>> > using vendor'd dependencies.
>>
>> Something like the following chunk of Bash would work (you could tweak
>> the Go list  invocation to just do vendored deps probably) if you have
>> graphviz installed (I can't remember where I got this, appologies if
>> I'm cribbing a script out of someones presentation without proper
>> attribution):
>>
>>     % ( echo "digraph G {"; \
>>     %   go list -f '{{range .Imports}}{{printf "\t%q -> %q;\n" \
>>     %     $.ImportPath .}}{{end}}' \
>>     %     $(go list -f '{{join .Deps " "}}' YOURPACKAGE) YOURPACKAGE;
>> \
>>     %   echo "}";
>>     % ) | dot -Tsvg -o $@
>>
>> —Sam
>>
>>
>> --
>> Sam Whited
>> pub 4096R/54083AE104EA7AD3
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to