diff --git a/.travis.yml b/.travis.yml index 65957d0..135e8de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,10 @@ env: - GO111MODULE=on script: - - if [ "$TRAVIS_OS_NAME" = "windows" ]; then CGO_ENABLED=0 go build -ldflags="-w -s" -o ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH.exe . ; fi - - if [ "$TRAVIS_OS_NAME" != "windows" ]; then CGO_ENABLED=0 go build -ldflags="-w -s" -o ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH . ; fi + - if [ "$TRAVIS_OS_NAME" = "windows" ]; then CGO_ENABLED=0 go build -ldflags="-w -s -X 'github.com/kernle32dll/ew/internal/cmd.buildBranch=$TRAVIS_BRANCH'" -o ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH.exe . ; fi + - if [ "$TRAVIS_OS_NAME" != "windows" ]; then CGO_ENABLED=0 go build -ldflags="-w -s -X 'github.com/kernle32dll/ew/internal/cmd.buildDate=$(date -u '+%Y/%m/%d %H:%M:%S')' -X 'github.com/kernle32dll/ew/internal/cmd.buildBranch=$TRAVIS_BRANCH'" -o ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH . ; fi + - if [ "$TRAVIS_OS_NAME" = "windows" ]; then ./ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH.exe --version ; fi + - if [ "$TRAVIS_OS_NAME" != "windows" ]; then ./ew-$TRAVIS_OS_NAME-$TRAVIS_CPU_ARCH --version ; fi - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... after_success: diff --git a/README.md b/README.md index a6ab1af..f9a2407 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ COMMAND | DESCRIPTION ew | list all paths, grouped by their tags ew help | displays this help ew --help | displays this help (alias for ew help) +ew version | displays version and build time (if applicable) +ew --version | displays version and build time (if applicable) (alias for ew version) ew migrate | migrate from mixu/gr config, and keep json format ew migrate --yaml | migrate from mixu/gr config, and use new yaml format ew paths | list all paths (alias for ew paths list) diff --git a/internal/cmd/cmd_help.go b/internal/cmd/cmd_help.go index c29f3e6..3615faf 100644 --- a/internal/cmd/cmd_help.go +++ b/internal/cmd/cmd_help.go @@ -25,6 +25,10 @@ func NewHelpCommand( func (c HelpCommand) Execute() error { fmt.Fprintln(c.output, "EW - (run things) e(very)w(here)") fmt.Fprintln(c.output, "Original author: Björn Gerdau") + + fmt.Fprint(c.output, "Version: ") + NewVersionCommand(c.output).Execute() + fmt.Fprintln(c.output) fmt.Fprintln(c.output, "Available commands:") @@ -33,6 +37,8 @@ func (c HelpCommand) Execute() error { {"ew", "list all paths, grouped by their tags"}, {"ew help", "displays this help"}, {"ew --help", ""}, + {"ew version", "displays version and build time (if applicable)"}, + {"ew --version", ""}, {"ew migrate", "migrate from mixu/gr config, and keep json format"}, {"ew migrate --yaml", "migrate from mixu/gr config, and use new yaml format"}, {"ew paths", "list all paths (alias for ew paths list)"}, diff --git a/internal/cmd/cmd_version.go b/internal/cmd/cmd_version.go new file mode 100644 index 0000000..b5d6c02 --- /dev/null +++ b/internal/cmd/cmd_version.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "fmt" + "io" +) + +var ( + buildBranch string + buildDate string +) + +// VersionCommand prints out the CLI help. +type VersionCommand struct { + output io.Writer +} + +// NewVersionCommand creates a new VersionCommand. +func NewVersionCommand( + output io.Writer, +) *VersionCommand { + return &VersionCommand{ + output: output, + } +} + +func (c VersionCommand) Execute() error { + if buildBranch == "" { + buildBranch = "master" + } + + if buildDate != "" { + fmt.Fprintf(c.output, "%s built %s\n", buildBranch, buildDate) + } else { + fmt.Fprintln(c.output, buildBranch) + } + + return nil +} diff --git a/internal/cmd/parser.go b/internal/cmd/parser.go index 2f2b084..e390db5 100644 --- a/internal/cmd/parser.go +++ b/internal/cmd/parser.go @@ -26,6 +26,8 @@ func ParseCommand(output io.Writer, conf internal.Config, args []string) (Comman switch args[0] { case "help", "--help": return NewHelpCommand(output), nil + case "version", "--version": + return NewVersionCommand(output), nil case "migrate": return NewMigrateCommand(output, len(args) == 2 && args[1] == "--yaml"), nil case "paths":