-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
56 lines (43 loc) · 1.27 KB
/
setup.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
51
52
53
54
55
56
package commands
import (
"fmt"
"os"
"github.com/avanibbles/flowflow/pkg"
"github.com/avanibbles/flowflow/pkg/config"
"github.com/avanibbles/flowflow/internal"
"github.com/spf13/cobra"
)
func SetupCommand(cmd *cobra.Command) {
cmd.AddCommand(versionCommand, serveCommand, configCommand, hackCommand)
}
var (
versionCommand = &cobra.Command{
Use: "version",
Short: "Print the current flowflow version",
RunE: func(_ *cobra.Command, _ []string) error {
conf, err := config.LoadConfigFromViper()
cobra.CheckErr(err)
var serverVersion string
if len(conf.Client.Host) > 0 {
api, err := pkg.NewApiClient(conf)
cobra.CheckErr(err)
resp, err := api.Version.GetAPIV1Version(nil)
if err != nil {
serverVersion = fmt.Sprintf("server: err: %s", err.Error())
} else {
serverVersion = fmt.Sprintf("%s-%s (%s)", resp.Payload.Version, resp.Payload.CommitHash, resp.Payload.BuildTimestamp)
serverVersion = fmt.Sprintf("server: %s", serverVersion)
}
}
localVersion := fmt.Sprintf("local: %s", internal.BuildVersion())
_, err = fmt.Fprintln(os.Stdout, localVersion)
if err != nil {
return err
}
if len(serverVersion) != 0 {
_, err = fmt.Fprintln(os.Stdout, serverVersion)
return err
}
return nil
}}
)