Skip to content

Commit

Permalink
boss version improved
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed May 6, 2022
1 parent da49a54 commit bc9a208
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ import (
"github.com/spf13/cobra"
)

var versionPrint bool

var RootCmd = &cobra.Command{
Use: "boss",
Short: "Dependency Manager for Delphi",
Long: "Dependency Manager for Delphi",
Run: func(cmd *cobra.Command, args []string) {
printVersion(false)
},
}

func Execute() {
RootCmd.PersistentFlags().BoolVarP(&env.Global, "global", "g", false, "global environment")
RootCmd.PersistentFlags().BoolVarP(&msg.DebugEnable, "debug", "d", false, "debug")
RootCmd.Flags().BoolVarP(&versionPrint, "version", "v", false, "show cli version")

msg.DebugEnable = utils.Contains(os.Args, "-d")

setup.Initialize()
Expand Down
18 changes: 13 additions & 5 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/hashload/boss/internal/version"
Expand All @@ -15,17 +16,24 @@ var versionCmd = &cobra.Command{
Example: ` Print version:
boss version`,
Run: func(cmd *cobra.Command, args []string) {
printVersion()
printVersion(true)
},
}

func init() {
RootCmd.AddCommand(versionCmd)
}

func printVersion() {
func printVersion(withDetails bool) {
v := version.Get()
fmt.Println("Version ", v.Version)
fmt.Println("Git commit ", v.GitCommit)
fmt.Println("Go version ", v.GoVersion)
if withDetails {
jsonVersion, err := json.MarshalIndent(v, "", " ")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(string(jsonVersion))
}
} else {
fmt.Println(v.Version)
}
}

0 comments on commit bc9a208

Please sign in to comment.