hub/commands/commands.go

98 строки
1.5 KiB
Go
Исходник Обычный вид История

2013-05-29 22:58:46 +04:00
package commands
import (
"flag"
"fmt"
"strings"
)
2013-06-30 20:00:21 +04:00
var (
NameRe = "[\\w.][\\w.-]*"
OwnerRe = "[a-zA-Z0-9][a-zA-Z0-9-]*"
2013-07-01 21:11:02 +04:00
NameWithOwnerRe = fmt.Sprintf("^(?:%s|%s\\/%s)$", NameRe, OwnerRe, NameRe)
2013-06-30 20:00:21 +04:00
)
2013-05-29 22:58:46 +04:00
type Command struct {
2013-06-26 19:48:34 +04:00
Run func(cmd *Command, args *Args)
2013-05-29 22:58:46 +04:00
Flag flag.FlagSet
2013-06-18 00:56:57 +04:00
Usage string
Short string
Long string
GitExtension bool
2013-05-29 22:58:46 +04:00
}
func (c *Command) PrintUsage() {
if c.Runnable() {
2013-12-14 19:22:23 +04:00
fmt.Printf("%s\n\n", c.FormattedUsage())
2013-05-29 22:58:46 +04:00
}
fmt.Println(strings.Trim(c.Long, "\n"))
2013-05-29 22:58:46 +04:00
}
2013-12-14 19:22:23 +04:00
func (c *Command) FormattedUsage() string {
return fmt.Sprintf("Usage: git %s", c.Usage)
}
2013-05-29 22:58:46 +04:00
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-07-04 09:07:23 +04:00
var Basic = []*Command{
2013-07-10 21:49:03 +04:00
cmdInit,
2013-07-04 09:07:23 +04:00
}
2013-06-21 22:40:42 +04:00
var Branching = []*Command{
cmdCheckout,
2013-07-02 20:59:02 +04:00
cmdMerge,
2013-07-11 22:23:59 +04:00
cmdApply,
2013-07-20 01:26:00 +04:00
cmdCherryPick,
2013-06-21 22:40:42 +04:00
}
2013-06-17 21:19:54 +04:00
var Remote = []*Command{
2013-07-01 21:11:02 +04:00
cmdClone,
2013-07-10 21:49:03 +04:00
cmdFetch,
2013-07-12 13:41:01 +04:00
cmdPush,
2013-06-17 21:19:54 +04:00
cmdRemote,
2013-07-13 12:19:42 +04:00
cmdSubmodule,
2013-06-17 21:19:54 +04:00
}
var GitHub = []*Command{
cmdPullRequest,
2013-06-11 04:10:40 +04:00
cmdFork,
2013-07-10 21:49:03 +04:00
cmdCreate,
cmdCiStatus,
2013-05-31 18:21:45 +04:00
cmdBrowse,
2013-06-03 04:04:25 +04:00
cmdCompare,
2013-12-20 03:49:36 +04:00
cmdReleases,
2013-09-26 23:49:01 +04:00
cmdRelease,
2013-10-24 03:25:21 +04:00
cmdIssue,
2013-05-29 22:58:46 +04:00
}
2013-06-18 01:15:59 +04:00
func All() []*Command {
2013-06-21 22:40:42 +04:00
all := make([]*Command, 0)
2013-07-05 03:18:54 +04:00
all = append(all, Basic...)
2013-06-21 22:40:42 +04:00
all = append(all, Branching...)
all = append(all, Remote...)
all = append(all, GitHub...)
2013-06-29 20:54:06 +04:00
all = append(all, cmdAlias)
2013-06-21 22:40:42 +04:00
all = append(all, cmdVersion)
2013-06-18 01:15:59 +04:00
all = append(all, cmdHelp)
2013-12-18 22:56:46 +04:00
all = append(all, cmdUpdate)
2013-06-18 01:15:59 +04:00
return all
}