Skip to content

Commit

Permalink
Merge pull request #15 from kyoshidajp/add_version_option
Browse files Browse the repository at this point in the history
Add version option
  • Loading branch information
kyoshidajp authored Jan 20, 2018
2 parents 606f8af + 6b8619f commit 686195a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INTERNAL_BIN_DIR=_internal_bin
GOVERSION=$(shell go version)
GOOS=$(word 1,$(subst /, ,$(lastword $(GOVERSION))))
GOARCH=$(word 2,$(subst /, ,$(lastword $(GOVERSION))))
VERSION=$(patsubst "%",%,$(lastword $(shell grep 'const version' main.go)))
VERSION=$(patsubst "%",%,$(lastword $(shell grep 'const Version' main.go)))
RELEASE_DIR=releases
ARTIFACTS_DIR=$(RELEASE_DIR)/artifacts/$(VERSION)
SRC_FILES = $(wildcard *.go)
Expand Down
10 changes: 10 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (c *CLI) Run(args []string) int {
url bool
apiurl bool
newline bool
version bool
)
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
flags.Usage = func() {
Expand All @@ -80,6 +81,8 @@ func (c *CLI) Run(args []string) int {
flags.BoolVar(&apiurl, "a", false, "")
flags.BoolVar(&newline, "newline", true, "")
flags.BoolVar(&newline, "n", true, "")
flags.BoolVar(&version, "version", true, "")
flags.BoolVar(&version, "v", true, "")

// Parse flag
if err := flags.Parse(args[1:]); err != nil {
Expand All @@ -91,6 +94,11 @@ func (c *CLI) Run(args []string) int {
Debugf("Run as DEBUG mode")
}

if version {
fmt.Fprintf(c.outStream, fmt.Sprintf("%s\n", Version))
return ExitCodeOK
}

parsedArgs := flags.Args()
if len(parsedArgs) != 1 {
PrintErrorf("Invalid argument: you must set sha.")
Expand Down Expand Up @@ -278,4 +286,6 @@ Options:
Print debug log.
-h, --help Show this help message and exit.
-v, --version Print current version.
`
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "os"

const version = "0.0.2"
const Version string = "0.0.2"

func main() {
cli := &CLI{outStream: os.Stdout, errStream: os.Stderr}
Expand Down

0 comments on commit 686195a

Please sign in to comment.