Skip to content

Commit

Permalink
enhance: make version output consistent (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored Mar 1, 2021
1 parent 32fe344 commit e32fba7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 46 deletions.
29 changes: 17 additions & 12 deletions cmd/vela-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@ import (
_ "github.com/joho/godotenv/autoload"
)

// nolint: funlen // ignore function length due to comments and flags
func main() {
// capture application version information
v := version.New()

// serialize the version information as pretty JSON
bytes, err := json.MarshalIndent(v, "", " ")
if err != nil {
logrus.Fatal(err)
}

// output the version information to stdout
fmt.Fprintf(os.Stdout, "%s\n", string(bytes))

// create new CLI application
app := cli.NewApp()

// Plugin Information
Expand All @@ -38,7 +52,7 @@ func main() {

app.Action = run
app.Compiled = time.Now()
app.Version = version.New().Semantic()
app.Version = v.Semantic()

// Plugin Flags

Expand Down Expand Up @@ -148,23 +162,14 @@ func main() {
},
}

err := app.Run(os.Args)
err = app.Run(os.Args)
if err != nil {
logrus.Fatal(err)
}
}

// run executes the plugin based off the configuration provided.
func run(c *cli.Context) error {
// capture the version information as pretty JSON
v, err := json.MarshalIndent(version.New(), "", " ")
if err != nil {
return err
}

// output the version information to stdout
fmt.Fprintf(os.Stdout, "%s\n", string(v))

// set the log level for the plugin
switch c.String("log.level") {
case "t", "trace", "Trace", "TRACE":
Expand Down Expand Up @@ -236,7 +241,7 @@ func run(c *cli.Context) error {
}

// validate the plugin
err = p.Validate()
err := p.Validate()
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit e32fba7

Please sign in to comment.