-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (56 loc) · 1.3 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
package main
import (
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/spachava753/kpkg/cmd"
"github.com/spachava753/kpkg/pkg/config"
"github.com/spachava753/kpkg/pkg/download"
"os"
"runtime"
)
var cliOs = runtime.GOOS
var cliArch = runtime.GOARCH
var (
version,
commit,
goVersion string
)
func main() {
if err := run(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
// fetch the users home dir
hDir, err := homedir.Dir()
if err != nil {
return err
}
// set up kpkg's necessary folders if not setup already (.kpkg, .kpkg/bin)
root, err := config.CreatePath(hDir)
if err != nil {
return err
}
// create instances of top level commands
rootCmd := cmd.MakeRoot()
getCmd := cmd.MakeGet()
listCmd := cmd.MakeList(root)
rmCmd := cmd.MakeRm(root)
versionCmd := cmd.MakeVersion(version, commit, goVersion)
fileFetcher, err := download.InitFileFetcher()
if err != nil {
return err
}
tools := cmd.GetTools(cliOs, cliArch)
cmd.MakeGetBinarySubCmds(root, getCmd, tools, fileFetcher, cliOs == "windows")
cmd.MakeListBinarySubCmds(listCmd, tools, root)
rootCmd.AddCommand(getCmd, listCmd, rmCmd, versionCmd)
// set outputs
rootCmd.SetOut(os.Stdout)
rootCmd.SetErr(os.Stderr)
if err := rootCmd.Execute(); err != nil {
return err
}
return nil
}