diff options
| author | Sam Dodrill <xena@yolo-swag.com> | 2015-02-15 22:05:26 -0800 |
|---|---|---|
| committer | Sam Dodrill <xena@yolo-swag.com> | 2015-02-15 22:05:26 -0800 |
| commit | d67a79be36f6e0cf3a9446d745b2d413a6a25d9b (patch) | |
| tree | 0c8fd9ce941e3bd3f9ba604539b31e6b8c59fcbc | |
| parent | 79f506a7875faefd57577beb72ae3b0cf7685650 (diff) | |
| download | x-d67a79be36f6e0cf3a9446d745b2d413a6a25d9b.tar.xz x-d67a79be36f6e0cf3a9446d745b2d413a6a25d9b.zip | |
license: make license write to stdout implicitly
| -rw-r--r-- | license/main.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/license/main.go b/license/main.go index cdff46a..fd3056b 100644 --- a/license/main.go +++ b/license/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "io" "log" "os" "os/exec" @@ -11,9 +12,9 @@ import ( ) var ( - name = flag.String("name", "", "name of the person licensing the software") - email = flag.String("email", "", "email of the person licensing the software") - outfile = flag.String("out", "LICENSE", "name of the file to write the output to") + name = flag.String("name", "", "name of the person licensing the software") + email = flag.String("email", "", "email of the person licensing the software") + out = flag.Bool("out", false, "write to a file instead of stdout") showAll = flag.Bool("show", false, "show all licenses instead of generating one") ) @@ -47,6 +48,8 @@ func main() { kind := flag.Arg(0) + outfile := "LICENSE" + var licensetext string if _, ok := licenses[kind]; !ok { fmt.Printf("invalid license kind %s\n", kind) @@ -55,8 +58,8 @@ func main() { licensetext = licenses[kind] - if kind == "unlicense" && *outfile == "LICENSE" { - *outfile = "UNLICENSE" + if kind == "unlicense" && *out { + outfile = "UNLICENSE" } if *name == "" { @@ -83,18 +86,27 @@ func main() { *email = myemail[:len(myemail)-1] } - fout, err := os.Create(*outfile) - if err != nil { - log.Fatal(err) + var wr io.Writer + + if *out { + fout, err := os.Create(outfile) + if err != nil { + log.Fatal(err) + } + defer fout.Close() + + wr = fout + } else { + wr = os.Stdout + defer fmt.Println() } - defer fout.Close() tmpl, err := template.New("license").Parse(licensetext) if err != nil { log.Fatal(err) } - err = tmpl.Execute(fout, struct { + err = tmpl.Execute(wr, struct { Name string Email string Year int |
