Skip to content

Commit

Permalink
Add version flag for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed Jun 12, 2019
1 parent dfbd63f commit 7874a6f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test:

.PHONY: build
build:
go build .
go build -ldflags='-X github.com/johnstarich/sage/consts.Version=${VERSION}'

.PHONY: docker
docker:
Expand Down
5 changes: 5 additions & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package consts

var (
Version string
)
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/johnstarich/sage/client"
"github.com/johnstarich/sage/consts"
"github.com/johnstarich/sage/ledger"
"github.com/johnstarich/sage/rules"
"github.com/johnstarich/sage/sync"
Expand Down Expand Up @@ -94,9 +95,15 @@ func handleErrors() (usageErr bool, err error) {
rulesFileName := flagSet.String("rules", "", "Required: Path to an hledger CSV import rules file")
ledgerFileName := flagSet.String("ledger", "", "Required: Path to a ledger file")
ofxClientFileName := flagSet.String("ofxclient", "", "Required: Path to an ofxclient ini file, includes connection information for institutions")
requestVersion := flagSet.Bool("version", false, "Print the version and exit")
if err := flagSet.Parse(os.Args[1:]); err != nil {
return true, err
}
if *requestVersion {
fmt.Println(consts.Version)
return false, nil
}

if err := requireFlags(flagSet); err != nil {
return true, errors.Errorf("%s\n%s", err.Error(), usage(flagSet))
}
Expand Down

0 comments on commit 7874a6f

Please sign in to comment.