-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.go
68 lines (57 loc) · 1.03 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
package main
import (
"errors"
"fmt"
"os"
"github.com/urfave/cli"
"github.com/manifoldco/torus-cli/cmd"
)
func lintCmd(c cli.Command) error {
var err error
order := []string{"create", "list", "view", "delete"}
var neworder []string
orderLoop:
for _, o := range order {
for _, s := range c.Subcommands {
if s.Names()[0] == o {
neworder = append(neworder, o)
continue orderLoop
}
}
}
for _, s := range c.Subcommands {
name := s.Names()[0]
if len(neworder) == 0 {
break
}
if neworder[0] == name {
neworder = neworder[1:]
}
for _, o := range neworder {
if o == name {
fmt.Printf("Error: %s standard subcommand '%s' out of order\n",
c.FullName(), name)
err = errors.New("subcommand out of order")
}
}
}
for _, s := range c.Subcommands {
newerr := lintCmd(s)
if newerr != nil {
err = newerr
}
}
return err
}
func main() {
var err error
for _, c := range cmd.Cmds {
newerr := lintCmd(c)
if newerr != nil {
err = newerr
}
}
if err != nil {
os.Exit(1)
}
}