Skip to content

Commit

Permalink
feat: add ability to print version (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHope authored Dec 8, 2023
1 parent 16c8994 commit 92445da
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ builds:
# ldflags:
# - -s
# - -w
# - -X "main.version={{ .Version }}"

# - id: armaria-darwin-arm64
# binary: armria
Expand All @@ -37,6 +38,7 @@ builds:
# ldflags:
# - -s
# - -w
# - -X "main.version={{ .Version }}"

- id: armaria-linux-amd64
binary: armaria
Expand All @@ -56,6 +58,7 @@ builds:
ldflags:
- -s
- -w
- -X "main.version={{ .Version }}"

- id: armaria-host-linux-amd64
binary: armaria-host
Expand Down Expand Up @@ -93,6 +96,7 @@ builds:
ldflags:
- -s
- -w
- -X "main.version={{ .Version }}"

- id: armaria-host-windows-amd64
binary: armaria-host
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks:
build-cli:
dir: cmd/cli
cmds:
- go build --tags "fts5"
- go build --tags "fts5" -ldflags="-X main.version=local"
- cp cli ../../armaria
build-host:
dir: cmd/host
Expand Down
13 changes: 13 additions & 0 deletions cmd/cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type RootCmd struct {

Config ConfigCmd `cmd:"" help:"Manage the configuration."`
Manifest ManifestCmd `cmd:"" help:"Manage the app manifest."`

Version VersionCmd `cmd:"" help:"Print the current version."`
}

// RootCmdFactory creates a new RootCmd.
Expand Down Expand Up @@ -759,3 +761,14 @@ func (r *InstallChromiumManifestCmd) Run(ctx *Context) error {

return nil
}

// VersionCmd is a CLI command to print the current version.
type VersionCmd struct {
}

// Run print the current version.
func (r *VersionCmd) Run(ctx *Context) error {
formatSuccess(ctx.Writer, ctx.Formatter, fmt.Sprintf(ctx.Version))

return nil
}
1 change: 1 addition & 0 deletions cmd/cli/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ type Context struct {
Formatter Formatter // how to format the output
Writer io.Writer // where to write output
ReturnCode func(int) // set the return code
Version string // the current version of Armaria
}
5 changes: 4 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/jonathanhope/armaria/cmd/cli/cmd"
)

var version string

func main() {
rootCmd := cmd.RootCmdFactory()
ctx := kong.Parse(&rootCmd)
Expand All @@ -15,7 +17,8 @@ func main() {
DB: rootCmd.DB,
Formatter: rootCmd.Formatter,
Writer: os.Stdout,
ReturnCode: os.Exit})
ReturnCode: os.Exit,
Version: version})

ctx.FatalIfErrorf(err)
}

0 comments on commit 92445da

Please sign in to comment.