2013-05-29 22:58:46 +04:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Command struct {
|
|
|
|
Run func(cmd *Command, args []string)
|
|
|
|
Flag flag.FlagSet
|
|
|
|
|
|
|
|
Usage string
|
|
|
|
Short string
|
|
|
|
Long string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) PrintUsage() {
|
|
|
|
if c.Runnable() {
|
|
|
|
fmt.Printf("Usage: gh %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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) List() bool {
|
|
|
|
return c.Short != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
var All = []*Command{
|
2013-06-05 22:36:40 +04:00
|
|
|
cmdPull,
|
|
|
|
cmdCi,
|
2013-05-31 18:21:45 +04:00
|
|
|
cmdBrowse,
|
2013-06-03 04:04:25 +04:00
|
|
|
cmdCompare,
|
2013-05-29 22:58:46 +04:00
|
|
|
cmdHelp,
|
|
|
|
cmdVersion,
|
|
|
|
}
|