-
Notifications
You must be signed in to change notification settings - Fork 45
/
root.go
68 lines (56 loc) · 1.58 KB
/
root.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
package cmd
import (
"fmt"
"os"
"strings"
"github.com/devops-works/binenv/internal/app"
"github.com/spf13/cobra"
)
// RootCmd returns the root cobra command
func RootCmd() *cobra.Command {
a, err := app.New(
// app.WithDiscard(),
// app.WithBinDir(bindir),
)
if err != nil {
fmt.Printf("got error %v\n", err)
panic(err)
}
rootCmd := &cobra.Command{
Use: "binenv",
Short: "Install binary distributions easily",
Long: `binenv lets you install binary-distributed applications
(e.g. terraform, kubectl, ...) easily and switch between any version.
If your directory has a '.binenv.lock', proper versions will always be
selected.`,
SilenceUsage: true,
}
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Verbose operation (env: BINENV_VERBOSE)")
rootCmd.PersistentFlags().BoolP("global", "g", false, "Global mode (env: BINENV_GLOBAL)")
rootCmd.PersistentFlags().StringP("bindir", "b", "", "Binaries directory")
if !strings.HasSuffix(os.Args[0], "binenv") {
verbose := truthify(os.Getenv("BINENV_VERBOSE"))
global := truthify(os.Getenv("BINENV_GLOBAL"))
a.SetGlobal(global)
a.SetVerbose(verbose)
a.Execute(os.Args)
}
rootCmd.AddCommand(
completionCmd(),
expandCmd(a),
installCmd(a),
localCmd(a),
searchCmd(a),
uninstallCmd(a),
updateCmd(a),
versionCmd(),
versionsCmd(a),
upgradeCmd(a),
)
return rootCmd
}
func truthify(s string) bool {
s = strings.ToLower(s)
// trueness suggestions courtesy of Github co-pilot
return s == "true" || s == "1" || s == "yes" || s == "y" || s == "on" || s == "enable" || s == "enabled" || s == "active"
}