-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.go
62 lines (49 loc) · 1022 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/tilt-dev/ctlptl/pkg/cmd"
"k8s.io/klog/v2"
)
// Magic variables set by goreleaser
var version string
var date string
func main() {
cmd.Version = version
command := cmd.NewRootCommand()
command.AddCommand(newVersionCommand())
klog.InitFlags(nil)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.VisitAll(func(f *pflag.Flag) {
f.Hidden = true
})
if err := command.Execute(); err != nil {
os.Exit(1)
}
}
func newVersionCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Current ctlptl version",
Run: func(_ *cobra.Command, args []string) {
fmt.Println(versionStamp())
},
}
}
func versionStamp() string {
timeIndex := strings.Index(date, "T")
if timeIndex != -1 {
date = date[0:timeIndex]
}
if date == "" {
date = "unknown"
}
if version == "" {
version = "0.0.0-main"
}
return fmt.Sprintf("v%s, built %s", version, date)
}