forked from bugficks/forego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
45 lines (37 loc) · 791 Bytes
/
command.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
package main
import (
"flag"
"fmt"
"strings"
)
var flagEnv string
var flagProcfile string
type Command struct {
// args does not include the command name
Run func(cmd *Command, args []string)
Flag flag.FlagSet
Disabled bool
Usage string // first word is the command name
Short string // `forego help` output
Long string // `forego help cmd` output
}
func (c *Command) printUsage() {
if c.Runnable() {
fmt.Printf("Usage: forego %s\n\n", c.Usage)
}
fmt.Println(strings.Trim(c.Long, "\n"))
}
func (c *Command) Name() string {
name := c.Usage
i := strings.Index(name, " ")
if i >= 0 {
name = name[:i]
}
return name
}
func (c *Command) Runnable() bool {
return c.Run != nil && c.Disabled != true
}
func (c *Command) List() bool {
return c.Short != ""
}