mirror of https://github.com/gogits/gogs.git
Unknown
12 years ago
5 changed files with 73 additions and 60 deletions
@ -0,0 +1,59 @@
|
||||
package cmd |
||||
|
||||
import ( |
||||
"flag" |
||||
"fmt" |
||||
"os" |
||||
"strings" |
||||
) |
||||
|
||||
var ( |
||||
reposDir string = "~/.gopm/repos" |
||||
) |
||||
|
||||
// A Command is an implementation of a go command
|
||||
// like go build or go fix.
|
||||
type Command struct { |
||||
// Run runs the command.
|
||||
// The args are the arguments after the command name.
|
||||
Run func(cmd *Command, args []string) |
||||
|
||||
// UsageLine is the one-line usage message.
|
||||
// The first word in the line is taken to be the command name.
|
||||
UsageLine string |
||||
|
||||
// Short is the short description shown in the 'go help' output.
|
||||
Short string |
||||
|
||||
// Long is the long message shown in the 'go help <this-command>' output.
|
||||
Long string |
||||
|
||||
// Flag is a set of flags specific to this command.
|
||||
Flag flag.FlagSet |
||||
|
||||
// CustomFlags indicates that the command will do its own
|
||||
// flag parsing.
|
||||
CustomFlags bool |
||||
} |
||||
|
||||
// Name returns the command's name: the first word in the usage line.
|
||||
func (c *Command) Name() string { |
||||
name := c.UsageLine |
||||
i := strings.Index(name, " ") |
||||
if i >= 0 { |
||||
name = name[:i] |
||||
} |
||||
return name |
||||
} |
||||
|
||||
func (c *Command) Usage() { |
||||
fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine) |
||||
fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long)) |
||||
os.Exit(2) |
||||
} |
||||
|
||||
// Runnable reports whether the command can be run; otherwise
|
||||
// it is a documentation pseudo-command such as importpath.
|
||||
func (c *Command) Runnable() bool { |
||||
return c.Run != nil |
||||
} |
Loading…
Reference in new issue