JMS #14: Improved help. Brought help commadn back to commands
This commit is contained in:
parent
f14b9c0d81
commit
63b9f2823a
6
app.go
6
app.go
@ -28,14 +28,18 @@ func NewApp() *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Run(arguments []string) {
|
func (a *App) Run(arguments []string) {
|
||||||
|
// parse flags
|
||||||
set := flagSet(a.Flags)
|
set := flagSet(a.Flags)
|
||||||
set.Parse(arguments[1:])
|
set.Parse(arguments[1:])
|
||||||
|
|
||||||
|
// append help to commands
|
||||||
|
a.Commands = append(a.Commands, HelpCommand)
|
||||||
|
|
||||||
context := NewContext(a, set, set)
|
context := NewContext(a, set, set)
|
||||||
args := context.Args()
|
args := context.Args()
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
name := args[0]
|
name := args[0]
|
||||||
for _, c := range append(a.Commands, HelpCommand) {
|
for _, c := range a.Commands {
|
||||||
if c.HasName(name) {
|
if c.HasName(name) {
|
||||||
c.Run(context)
|
c.Run(context)
|
||||||
return
|
return
|
||||||
|
5
help.go
5
help.go
@ -8,10 +8,7 @@ var HelpCommand = Command{
|
|||||||
Name: "help",
|
Name: "help",
|
||||||
ShortName: "h",
|
ShortName: "h",
|
||||||
Usage: "Shows a list of commands or help for one command",
|
Usage: "Shows a list of commands or help for one command",
|
||||||
}
|
Action: ShowHelp,
|
||||||
|
|
||||||
func init() {
|
|
||||||
HelpCommand.Action = ShowHelp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowHelp(c *Context) {
|
func ShowHelp(c *Context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user