diff --git a/.github/build b/.github/build index 7eff80d..f126fd9 100755 --- a/.github/build +++ b/.github/build @@ -33,6 +33,6 @@ for OS in ${BUILD_PLATFORMS[@]}; do export CGO_ENABLED=0 # Build the main-binary - go build -ldflags "-X main.version=$(git describe --tags 2>/dev/null || echo 'master')" -o "${BASE}-${SUFFIX}" + go build -ldflags "-X main.versionString=$(git describe --tags 2>/dev/null || echo 'master')" -o "${BASE}-${SUFFIX}" done done diff --git a/README.md b/README.md index d463304..99c195b 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,11 @@ Validate JSON files for correctness and syntax-errors. Validate XML files for correctness and syntax-errors. +## version + +Report the version of the binary, when downloaded from our [release page](https://github.com/skx/sysbox/releases). + + ## validate-yaml Validate YAML files for correctness and syntax-errors. diff --git a/cmd_version.go b/cmd_version.go new file mode 100644 index 0000000..b5e348e --- /dev/null +++ b/cmd_version.go @@ -0,0 +1,42 @@ +package main + +//go:generate echo Hello, Go Generate! +import ( + "fmt" + + "github.com/skx/subcommands" +) + +var ( + versionString = "unreleased" +) + +// Structure for our options and state. +type versionCommand struct { + + // We embed the NoFlags option, because we accept no command-line flags. + subcommands.NoFlags +} + +// Info returns the name of this subcommand. +func (t *versionCommand) Info() (string, string) { + return "version", `Show the version of the binary. + +Details: + +This reports upon the version of the sysbox application. + +Usage: + + $ sysbox version + +` +} + +// Execute is invoked if the user specifies `version` as the subcommand. +func (t *versionCommand) Execute(args []string) int { + + fmt.Printf("%s\n", versionString) + + return 0 +} diff --git a/main.go b/main.go index 97b9a7a..8d814ca 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,7 @@ func main() { subcommands.Register(&validateJSONCommand{}) subcommands.Register(&validateXMLCommand{}) subcommands.Register(&validateYAMLCommand{}) + subcommands.Register(&versionCommand{}) subcommands.Register(&withLockCommand{}) //