Skip to content

Commit 47c524b

Browse files
authored
Merge pull request davecheney#9 from aurelien-rainone/master
Flag to print to standard output
2 parents be829c6 + bb84145 commit 47c524b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ To graph the dependencies of the net package:
1515
graphpkg can also filter out packages that do not match the supplied regex, this may improve the readability of some graphs by excluding the std library:
1616

1717
graphpkg -match 'launchpad.net' launchpad.net/goamz/s3
18+
19+
# Output
20+
21+
By default graphpkg shows the graph in your browser, you can choose to print the resulting svg to standard output:
22+
23+
graphpkg -stdout -match 'github.com' github.com/davecheney/graphpkg

main.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"flag"
1313
"fmt"
1414
"go/build"
15+
"io"
1516
"log"
1617
"os"
1718
"os/exec"
@@ -23,6 +24,7 @@ import (
2324
var (
2425
pkgs = make(map[string][]string)
2526
matchvar = flag.String("match", ".*", "filter packages")
27+
stdout = flag.Bool("stdout", false, "print to standard output instead of browser")
2628
pkgmatch *regexp.Regexp
2729
)
2830

@@ -117,13 +119,20 @@ func main() {
117119
fmt.Fprintf(in, "}\n")
118120
in.Close()
119121

120-
ch := make(chan error)
121-
go func() {
122-
ch <- browser.OpenReader(out)
122+
if *stdout {
123+
// print to standard output
124+
io.Copy(os.Stdout, out)
123125

124-
}()
125-
check(cmd.Wait())
126-
if err := <-ch; err != nil {
127-
log.Fatalf("unable to open browser: %s", err)
126+
} else {
127+
// pipe output to browser
128+
ch := make(chan error)
129+
go func() {
130+
ch <- browser.OpenReader(out)
131+
132+
}()
133+
check(cmd.Wait())
134+
if err := <-ch; err != nil {
135+
log.Fatalf("unable to open browser: %s", err)
136+
}
128137
}
129138
}

0 commit comments

Comments
 (0)