Skip to content

Commit

Permalink
Added version sub-command. (#38)
Browse files Browse the repository at this point in the history
* Added `version` sub-command.

This reports "unreleased" when built from the git-repository, but
will report the tag/release information when autogenerated releases
are built via the github-action.

This closes #37.

* Document the 'version' subcommand
  • Loading branch information
skx authored Nov 6, 2021
1 parent 14e5560 commit 27ce063
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/build
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions cmd_version.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func main() {
subcommands.Register(&validateJSONCommand{})
subcommands.Register(&validateXMLCommand{})
subcommands.Register(&validateYAMLCommand{})
subcommands.Register(&versionCommand{})
subcommands.Register(&withLockCommand{})

//
Expand Down

0 comments on commit 27ce063

Please sign in to comment.