Skip to content

Commit

Permalink
Add version to cli. Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
diogox committed Feb 25, 2021
1 parent f2aa1d3 commit 23f6c96
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
goversion: "https://golang.org/dl/go1.15.7.linux-amd64.tar.gz"
project_path: ./cmd/bspm
binary_name: bspm
ldflags: "-s -w"
ldflags: "-s -w -X 'main.Version=${{ github.event.release.tag_name }}'"
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.PHONY: generate
.PHONY: generate install

install:
go install -ldflags="-s -w -X 'main.Version=local'" ./cmd/bspm

generate: clean-mock
rm -rf vendor
Expand Down
4 changes: 3 additions & 1 deletion cmd/bspm/bspm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/diogox/bspm/internal/cli"
)

var Version string

func main() {
logger, err := zap.NewProduction()
if err != nil {
Expand All @@ -17,7 +19,7 @@ func main() {
_ = logger.Sync()
}()

if err := cli.New(logger).Run(); err != nil {
if err := cli.New(logger, Version).Run(); err != nil {
logger.Error("failed to run desired command", zap.Error(err))
return
}
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ type app struct {
cli *cli.App
}

func New(logger *zap.Logger) app {
func New(logger *zap.Logger, version string) app {
return app{
cli: &cli.App{
Name: "bspm",
Usage: "the bspwm manager",
Name: "bspm",
Usage: "the bspwm manager",
Version: version,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: flagKeyDaemon,
Aliases: []string{"d"},
Usage: "run the manager deamon",
},
&cli.BoolFlag{
Name: flagKeyVerbose,
Aliases: []string{"v"},
Usage: "verbose logging",
Name: flagKeyVerbose,
Usage: "verbose logging",
},
},
Commands: []*cli.Command{
Expand Down

0 comments on commit 23f6c96

Please sign in to comment.