Skip to content

Commit

Permalink
Merge pull request #2 from kernle32dll/version-test
Browse files Browse the repository at this point in the history
Add version command
  • Loading branch information
kernle32dll authored Oct 9, 2020
2 parents e60f67e + e86a4d7 commit db6bdb9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/cmd_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")

Expand All @@ -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)"},
Expand Down
39 changes: 39 additions & 0 deletions internal/cmd/cmd_version.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions internal/cmd/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit db6bdb9

Please sign in to comment.