-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
137 lines (114 loc) · 3.24 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"fmt"
"io"
"os"
"runtime"
"github.com/spf13/cobra"
"github.com/myhro/staticd/tools"
)
var version = "dev"
func exit(msg string) {
//nolint:errcheck
io.WriteString(os.Stderr, fmt.Sprintf("Error: %v\n", msg))
os.Exit(1)
}
func run(name string, version string) {
tool := &tools.Tool{
Name: name,
User: &tools.UserOS{},
Version: version,
}
err := tool.SetURL()
if err != nil {
exit(err.Error())
}
err = tool.SetRuntime(runtime.GOARCH, runtime.GOOS)
if err != nil {
exit(err.Error())
}
fmt.Println("Checking version for", tool.Name)
err = tool.GetVersion()
if err != nil {
exit(err.Error())
}
err = tool.SetAsset()
if err != nil {
exit(err.Error())
}
fmt.Println("Downloading version", tool.Version)
err = tool.Download()
if err != nil {
exit(err.Error())
}
fmt.Println("Downloaded", tool.Asset.Name)
if !tool.Asset.IsBinary {
fmt.Println("Extracting binary")
err := tool.Extract()
if err != nil {
exit(err.Error())
}
}
fmt.Println("Done")
}
func newCommand(name string, description string) *cobra.Command {
return &cobra.Command{
Use: name + " [version]",
Short: description,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
version := "latest"
if len(args) == 1 {
version = args[0]
}
run(name, version)
},
}
}
func main() {
rootCmd := &cobra.Command{
Use: "staticd",
Short: "Download statically linked binaries from GitHub",
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
}
batCmd := newCommand(tools.Bat, "A cat(1) clone with wings")
bottomCmd := newCommand(tools.Bottom, "Yet another cross-platform graphical process/system monitor")
cloudflaredCmd := newCommand(tools.Cloudflared, "Argo Tunnel client")
flyctlCmd := newCommand(tools.Flyctl, "Command line tools for fly.io services")
hugoCmd := newCommand(tools.Hugo, "The world's fastest framework for building websites")
k9sCmd := newCommand(tools.K9s, "Kubernetes CLI To Manage Your Clusters In Style")
kubectxCmd := newCommand(tools.Kubectx, "Faster way to switch between clusters in kubectl")
ripgrepCmd := newCommand(tools.Ripgrep, "Recursively searches directories for a regex pattern")
shellcheckCmd := newCommand(tools.Shellcheck, "A static analysis tool for shell scripts")
upxCmd := newCommand(tools.UPX, "The Ultimate Packer for eXecutables")
uvCmd := newCommand(tools.Uv, "An extremely fast Python package and project manager")
xhCmd := newCommand(tools.Xh, "Friendly and fast tool for sending HTTP requests")
yjCmd := newCommand(tools.Yj, "Convert between YAML, TOML, JSON, and HCL")
versionCmd := &cobra.Command{
Use: "version",
Short: "Show version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},
}
rootCmd.AddCommand(batCmd)
rootCmd.AddCommand(bottomCmd)
rootCmd.AddCommand(cloudflaredCmd)
rootCmd.AddCommand(flyctlCmd)
rootCmd.AddCommand(hugoCmd)
rootCmd.AddCommand(k9sCmd)
rootCmd.AddCommand(kubectxCmd)
rootCmd.AddCommand(ripgrepCmd)
rootCmd.AddCommand(shellcheckCmd)
rootCmd.AddCommand(upxCmd)
rootCmd.AddCommand(uvCmd)
rootCmd.AddCommand(xhCmd)
rootCmd.AddCommand(yjCmd)
rootCmd.AddCommand(versionCmd)
err := rootCmd.Execute()
if err != nil {
exit(err.Error())
}
}