Skip to content

Feature Request: Set Command.Version to enable built-in --version flag #121

@zaidshabbir25

Description

@zaidshabbir25

Summary

ACE uses urfave/cli/v3, which provides a built-in -v/--version flag via
cli.VersionFlag. However, the flag is only registered when the root
Command.Version field is set. ACE does not set it, so ace --version fails:

$ ace --version
Incorrect Usage: flag provided but not defined: -version

Current Workaround

The only way to determine the version today is inspecting Go build metadata:

$ go version -m /usr/bin/ace
mod github.com/pgedge/ace v1.9.1-0.20260525173524-40465f03d62e

This returns a pseudo-version, not a clean release identifier, and is not
practical for end users.

Proposed Fix

Since the framework already handles the flag, the change is minimal:

  1. Add build-time version variables in the main package:

    var (
    version = "dev"
    commit = "none"
    date = "unknown"
    )

  2. Set the Version field on the root command:

    cmd := &cli.Command{
    Name: "ace",
    Version: version,
    // ...
    }

  3. (Optional) Customize the printer to include commit + build date:

    cli.VersionPrinter = func(cmd *cli.Command) {
    fmt.Printf("ACE %s (commit: %s, built: %s)\n", version, commit, date)
    }

  4. Inject values at build time via ldflags:

    go build -ldflags "
    -X main.version=$(git describe --tags)
    -X main.commit=$(git rev-parse --short HEAD)
    -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
    ./cmd/ace

Expected Result

$ ace --version
ACE v1.9.1 (commit: 40465f0, built: 2026-05-25T17:35:24Z)

Benefits

  • Uses framework's existing flag — no custom parsing
  • Clean version for support, bug reports, and CI/CD
  • Build metadata (commit/date) aids debugging pre-release builds

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions