-
Notifications
You must be signed in to change notification settings - Fork 239
/
version.go
74 lines (58 loc) · 1.49 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Package version implements the version command chain.
package version
import (
"context"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/internal/buildinfo"
"github.com/superfly/flyctl/internal/cache"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
)
const saveInstallName = "saveinstall"
// New initializes and returns a new version Command.
func New() *cobra.Command {
const (
short = "Show version information for the flyctl command"
long = `Shows version information for the flyctl command itself, including version
number and build date.`
)
version := command.New("version", short, long, run)
// TODO: remove once installer is updated to use init-state
flag.Add(version,
flag.String{
Name: saveInstallName,
Shorthand: "s",
Description: "Save parameter in config",
},
)
version.AddCommand(
newInitState(),
newUpdate(),
)
return version
}
func run(ctx context.Context) (err error) {
if saveInstall := flag.GetString(ctx, saveInstallName); saveInstall != "" {
err = executeInitState(
iostreams.FromContext(ctx),
cache.FromContext(ctx),
saveInstall,
)
return
}
var (
cfg = config.FromContext(ctx)
info = buildinfo.Info()
out = iostreams.FromContext(ctx).Out
)
if cfg.JSONOutput {
err = json.NewEncoder(out).Encode(info)
} else {
_, err = fmt.Fprintln(out, info)
}
return
}