Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
-
name: Run tests
run: make test
-
-
name: Upload code coverage report
uses: codecov/codecov-action@v1
with:
Expand Down
26 changes: 22 additions & 4 deletions internal/cmd/version_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"encoding/json"
"flag"
"fmt"
"runtime"
"strings"

"github.com/mitchellh/cli"
)

type VersionOutput struct {
Version string `json:"version"`

*BuildInfo
}

type VersionCommand struct {
Expand All @@ -20,6 +23,13 @@ type VersionCommand struct {
jsonOutput bool
}

type BuildInfo struct {
GoVersion string `json:"go,omitempty"`
GoOS string `json:"os,omitempty"`
GoArch string `json:"arch,omitempty"`
Compiler string `json:"compiler,omitempty"`
}

func (c *VersionCommand) flags() *flag.FlagSet {
fs := defaultFlagSet("version")

Expand All @@ -37,10 +47,17 @@ func (c *VersionCommand) Run(args []string) int {
return 1
}

output := VersionOutput{
Version: c.Version,
BuildInfo: &BuildInfo{
GoVersion: runtime.Version(),
GoOS: runtime.GOOS,
GoArch: runtime.GOARCH,
Compiler: runtime.Compiler,
},
}

if c.jsonOutput {
output := VersionOutput{
Version: c.Version,
}
jsonOutput, err := json.MarshalIndent(output, "", " ")
if err != nil {
c.Ui.Error(fmt.Sprintf("\nError marshalling JSON: %s", err))
Expand All @@ -50,7 +67,8 @@ func (c *VersionCommand) Run(args []string) int {
return 0
}

c.Ui.Output(string(c.Version))
ver := fmt.Sprintf("%s\nplatform: %s/%s\ngo: %s\ncompiler: %s", c.Version, output.GoOS, output.GoArch, output.GoVersion, output.Compiler)
c.Ui.Output(ver)
return 0
}

Expand Down