Skip to content

Commit

Permalink
Merge pull request #12 from Songmu/version
Browse files Browse the repository at this point in the history
 add -version flag to print version
  • Loading branch information
Songmu committed Feb 17, 2019
2 parents 8d4e210 + f552a8a commit 8dab99e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions godzil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godzil

import (
"flag"
"fmt"
"io"
"log"

Expand All @@ -11,12 +12,17 @@ import (
// Run the godzil
func Run(argv []string, outStream, errStream io.Writer) error {
log.SetOutput(errStream)
// global flagset
fs := flag.NewFlagSet("godzil", flag.ContinueOnError)
fs := flag.NewFlagSet(
fmt.Sprintf("godzil (v%s rev:%s)", version, revision), flag.ContinueOnError)
fs.SetOutput(errStream)
ver := fs.Bool("version", false, "display version")
if err := fs.Parse(argv); err != nil {
return err
}
if *ver {
return printVersion(outStream)
}

argv = fs.Args()
if len(argv) < 1 {
return xerrors.New("no subcommand specified")
Expand All @@ -28,6 +34,11 @@ func Run(argv []string, outStream, errStream io.Writer) error {
return rnr.run(argv[1:], outStream, errStream)
}

func printVersion(out io.Writer) error {
_, err := fmt.Fprintf(out, "godzil v%s (rev:%s)\n", version, revision)
return err
}

var dispatch = map[string]runner{
"release": &release{},
"new": &new{},
Expand Down

0 comments on commit 8dab99e

Please sign in to comment.