-
Notifications
You must be signed in to change notification settings - Fork 221
/
version.go
67 lines (53 loc) · 1.39 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
// 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/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
)
// 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: "saveinstall",
Shorthand: "s",
Description: "Save parameter in config",
Hidden: true,
},
)
version.AddCommand(
newSaveInstall(),
newUpgrade(),
)
flag.Add(version, flag.JSONOutput())
return version
}
func run(ctx context.Context) (err error) {
if channel := flag.GetString(ctx, "saveinstall"); channel != "" {
return saveInstall(ctx, channel, true)
}
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
}