-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
75 lines (61 loc) · 1.39 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
package main
import (
"path/filepath"
"github.com/tj/docopt"
"github.com/tj/robo/cli"
"github.com/tj/robo/config"
)
var version = "0.8.0"
const usage = `
Usage:
robo [-q] [--config file]
robo <task> [<arg>...] [--config file]
robo help [<task>] [--config file]
robo variables [--config file]
robo -h | --help
robo --version
Options:
-c, --config file config file to load [default: robo.yml]
-h, --help output help information
-v, --version output version
-q, --quiet output task names only
Examples:
output tasks
$ robo
output task help
$ robo help mytask
`
func main() {
args, err := docopt.Parse(usage, nil, true, version, true)
if err != nil {
cli.Fatalf("error parsing arguments: %s", err)
}
abs, err := filepath.Abs(args["--config"].(string))
if err != nil {
cli.Fatalf("cannot resolve --config: %s", err)
}
c, err := config.New(abs)
if err != nil {
cli.Fatalf("error loading configuration: %s", err)
}
switch {
case args["help"].(bool):
if name, ok := args["<task>"].(string); ok {
cli.Help(c, name)
} else {
cli.List(c)
}
case args["variables"].(bool):
cli.ListVariables(c)
default:
if name, ok := args["<task>"].(string); ok {
cli.Run(c, name, args["<arg>"].([]string))
return
}
if args["--quiet"].(bool) {
cli.ListNames(c)
} else {
cli.List(c)
}
}
}