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 != ""
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:19:54 +04:00
|
|
|
var All = append(Remote, GitHub...)
|
|
|
|
|
|
|
|
var Remote = []*Command{
|
|
|
|
cmdRemote,
|
|
|
|
}
|
|
|
|
|
|
|
|
var GitHub = []*Command{
|
2013-06-05 22:36:40 +04:00
|
|
|
cmdPull,
|
2013-06-11 04:10:40 +04:00
|
|
|
cmdFork,
|
2013-06-05 22:36:40 +04:00
|
|
|
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,
|
|
|
|
}
|