зеркало из https://github.com/mislav/hub.git
98 строки
1.5 KiB
Go
98 строки
1.5 KiB
Go
package commands
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
NameRe = "[\\w.][\\w.-]*"
|
|
OwnerRe = "[a-zA-Z0-9][a-zA-Z0-9-]*"
|
|
NameWithOwnerRe = fmt.Sprintf("^(?:%s|%s\\/%s)$", NameRe, OwnerRe, NameRe)
|
|
)
|
|
|
|
type Command struct {
|
|
Run func(cmd *Command, args *Args)
|
|
Flag flag.FlagSet
|
|
|
|
Usage string
|
|
Short string
|
|
Long string
|
|
GitExtension bool
|
|
}
|
|
|
|
func (c *Command) PrintUsage() {
|
|
if c.Runnable() {
|
|
fmt.Printf("%s\n\n", c.FormattedUsage())
|
|
}
|
|
|
|
fmt.Println(strings.Trim(c.Long, "\n"))
|
|
}
|
|
|
|
func (c *Command) FormattedUsage() string {
|
|
return fmt.Sprintf("Usage: git %s", c.Usage)
|
|
}
|
|
|
|
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 Basic = []*Command{
|
|
cmdInit,
|
|
}
|
|
|
|
var Branching = []*Command{
|
|
cmdCheckout,
|
|
cmdMerge,
|
|
cmdApply,
|
|
cmdCherryPick,
|
|
}
|
|
|
|
var Remote = []*Command{
|
|
cmdClone,
|
|
cmdFetch,
|
|
cmdPush,
|
|
cmdRemote,
|
|
cmdSubmodule,
|
|
}
|
|
|
|
var GitHub = []*Command{
|
|
cmdPullRequest,
|
|
cmdFork,
|
|
cmdCreate,
|
|
cmdCiStatus,
|
|
cmdBrowse,
|
|
cmdCompare,
|
|
cmdReleases,
|
|
cmdRelease,
|
|
cmdIssue,
|
|
}
|
|
|
|
func All() []*Command {
|
|
all := make([]*Command, 0)
|
|
all = append(all, Basic...)
|
|
all = append(all, Branching...)
|
|
all = append(all, Remote...)
|
|
all = append(all, GitHub...)
|
|
all = append(all, cmdAlias)
|
|
all = append(all, cmdVersion)
|
|
all = append(all, cmdHelp)
|
|
all = append(all, cmdUpdate)
|
|
|
|
return all
|
|
}
|