-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
76 lines (71 loc) · 1.86 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
package main
import "fmt"
import "licensezero.com/cli/subcommands"
import "github.com/mitchellh/go-homedir"
import "os"
import "sort"
// Rev represents the current build revision. Set via ldflags.
var Rev string
var commands = map[string]*subcommands.Subcommand{
"backup": subcommands.Backup,
"bugs": subcommands.Bugs,
"identify": subcommands.Identify,
"latest": subcommands.Latest,
"lock": subcommands.Lock,
"offer": subcommands.Offer,
"offers": subcommands.Offers,
"raise": subcommands.Raise,
"register": subcommands.Register,
"reprice": subcommands.Reprice,
"reset": subcommands.Reset,
"retract": subcommands.Retract,
"token": subcommands.Token,
"version": subcommands.Version,
"freebie": subcommands.Freebie,
"whoami": subcommands.WhoAmI,
}
func main() {
home, homeError := homedir.Dir()
if homeError != nil {
subcommands.Fail("Could not find home directory.")
}
cwd, cwdError := os.Getwd()
if cwdError != nil {
subcommands.Fail("Could not find working directory.")
}
paths := subcommands.Paths{Home: home, CWD: cwd}
arguments := os.Args
if len(arguments) > 1 {
subcommand := os.Args[1]
if value, ok := commands[subcommand]; ok {
if subcommand == "version" || subcommand == "latest" {
value.Handler([]string{Rev}, paths)
} else {
value.Handler(os.Args[2:], paths)
}
} else {
showUsage()
os.Exit(1)
}
} else {
showUsage()
os.Exit(0)
}
}
func showUsage() {
os.Stdout.WriteString("Manage License Zero offers.\n\nSubcommands:\n")
longestSubcommand := 0
var names []string
for name := range commands {
length := len(name) + 1
if length > longestSubcommand {
longestSubcommand = length
}
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
info := commands[name]
fmt.Printf(" %-"+fmt.Sprintf("%d", longestSubcommand)+"s %s\n", name, info.Description)
}
}