-
Notifications
You must be signed in to change notification settings - Fork 464
/
version.go
50 lines (45 loc) · 988 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cmd
import (
"fmt"
"os"
"github.com/autonomy/dianemo/src/initramfs/cmd/osctl/pkg/client"
"github.com/autonomy/dianemo/src/initramfs/pkg/version"
"github.com/spf13/cobra"
)
var (
shortVersion bool
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if shortVersion {
version.PrintShortVersion()
} else {
if err := version.PrintLongVersion(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
creds, err := client.NewDefaultClientCredentials()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
c, err := client.NewClient(port, creds)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := c.Version(); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
func init() {
versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print the short version")
rootCmd.AddCommand(versionCmd)
}