forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.go
82 lines (68 loc) · 1.57 KB
/
start.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
package main
import (
"fmt"
"strings"
)
// Version is the version of the cli.
// This is set by a build flag in the `Rakefile`.
var Version = "dev"
// GitSHA is the git sha of the build
// This is set by a build flag in the `Rakefile`.
var GitSHA = ""
// Channel is the git branch the code was compiled on.
// This is set by a build flag in the `Rakefile` based on the git branch.
var Channel = "?"
// CLITopics are all the command topics
// This list is all the Go topics, the Node topics are filled in later
var CLITopics Topics
// Args is os.Args
var Args []string
// Start the CLI
func Start(args ...string) {
Args = args
loadNewCLI()
ShowDebugInfo()
if len(Args) <= 1 {
// show dashboard if no args passed
Args = append(Args, "dashboard")
}
switch Args[1] {
case "_":
guess := loadLastCommandGuess()
if guess != nil {
Args = append([]string{Args[0], guess.Guess}, guess.Args...)
}
case "help", "--help", "-h":
help()
return
case "version", "--version", "-v":
ShowVersion()
return
}
for _, arg := range Args {
if arg == "--help" || arg == "-h" {
help()
return
}
}
cmd := AllCommands().Find(Args[1])
if cmd == nil {
helpInvalidCommand()
return
}
if !cmd.DisableAnalytics {
currentAnalyticsCommand.RecordStart()
}
ctx, err := BuildContext(cmd, Args)
must(err)
cmd.Run(ctx)
}
var crashing = false
// ShowDebugInfo prints debugging information if HEROKU_DEBUG=1
func ShowDebugInfo() {
info := []string{version(), BinPath}
if len(Args) > 1 {
info = append(info, fmt.Sprintf("cmd: %s", Args[1]))
}
Debugln(strings.Join(info, " "))
}