Skip to content

Commit bc9a208

Browse files
boss version improved
1 parent da49a54 commit bc9a208

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

cmd/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16+
var versionPrint bool
17+
1618
var RootCmd = &cobra.Command{
1719
Use: "boss",
1820
Short: "Dependency Manager for Delphi",
1921
Long: "Dependency Manager for Delphi",
22+
Run: func(cmd *cobra.Command, args []string) {
23+
printVersion(false)
24+
},
2025
}
2126

2227
func Execute() {
2328
RootCmd.PersistentFlags().BoolVarP(&env.Global, "global", "g", false, "global environment")
2429
RootCmd.PersistentFlags().BoolVarP(&msg.DebugEnable, "debug", "d", false, "debug")
30+
RootCmd.Flags().BoolVarP(&versionPrint, "version", "v", false, "show cli version")
31+
2532
msg.DebugEnable = utils.Contains(os.Args, "-d")
2633

2734
setup.Initialize()

cmd/version.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56

67
"github.com/hashload/boss/internal/version"
@@ -15,17 +16,24 @@ var versionCmd = &cobra.Command{
1516
Example: ` Print version:
1617
boss version`,
1718
Run: func(cmd *cobra.Command, args []string) {
18-
printVersion()
19+
printVersion(true)
1920
},
2021
}
2122

2223
func init() {
2324
RootCmd.AddCommand(versionCmd)
2425
}
2526

26-
func printVersion() {
27+
func printVersion(withDetails bool) {
2728
v := version.Get()
28-
fmt.Println("Version ", v.Version)
29-
fmt.Println("Git commit ", v.GitCommit)
30-
fmt.Println("Go version ", v.GoVersion)
29+
if withDetails {
30+
jsonVersion, err := json.MarshalIndent(v, "", " ")
31+
if err != nil {
32+
fmt.Println(err)
33+
} else {
34+
fmt.Println(string(jsonVersion))
35+
}
36+
} else {
37+
fmt.Println(v.Version)
38+
}
3139
}

0 commit comments

Comments
 (0)