From 04a20ba80d98159b918d2163796626f033597bfa Mon Sep 17 00:00:00 2001 From: Mason Sharp Date: Thu, 2 Jul 2026 14:40:57 -0700 Subject: [PATCH] feat(cli): add --version flag Leverage urfave/cli/v3's built-in Version support by setting the root command's Version field. Default is 2.1.0, overridden at release time via the existing goreleaser -X main.version ldflag. Use -V (not the default -v) as the short alias so -v stays reserved for the debug/verbose flag on subcommands. --- cmd/ace/main.go | 7 ++++++- internal/cli/cli.go | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/ace/main.go b/cmd/ace/main.go index e0f72fc..b858a70 100644 --- a/cmd/ace/main.go +++ b/cmd/ace/main.go @@ -22,6 +22,11 @@ import ( "github.com/pgedge/ace/pkg/logger" ) +// version is the ACE release version. It defaults to the value below for +// local builds and is overridden at release time via -ldflags "-X main.version=..." +// (see .goreleaser.yaml). +var version = "2.1.0" + func main() { var cfgPath string if !shouldSkipConfig(os.Args[1:]) { @@ -60,7 +65,7 @@ func main() { } } - app := cli.SetupCLI() + app := cli.SetupCLI(version) err := app.Run(context.Background(), os.Args) if err != nil { logger.Error("%v", err) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index c9c5a4f..e91e58d 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -43,7 +43,15 @@ var defaultConfigYAML string //go:embed default_pg_service.conf var defaultPgServiceConf string -func SetupCLI() *cli.Command { +func SetupCLI(version string) *cli.Command { + // Use -V (not the urfave default -v) for version, so -v stays reserved for + // the debug/verbose flag on subcommands (matching go tooling conventions). + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", + Aliases: []string{"V"}, + Usage: "print the version", + } + commonFlags := []cli.Flag{ &cli.StringFlag{ Name: "dbname", @@ -433,8 +441,9 @@ func SetupCLI() *cli.Command { } app := &cli.Command{ - Name: "ace", - Usage: "ACE - Active Consistency Engine", + Name: "ace", + Usage: "ACE - Active Consistency Engine", + Version: version, Commands: []*cli.Command{ { Name: "config",