@ -81,10 +81,10 @@ var helpCommand = Command{
Action : func ( c * Context ) error {
Action : func ( c * Context ) error {
args := c . Args ( )
args := c . Args ( )
if args . Present ( ) {
if args . Present ( ) {
ShowCommandHelp ( c , args . First ( ) )
return ShowCommandHelp ( c , args . First ( ) )
} else {
ShowAppHelp ( c )
}
}
ShowAppHelp ( c )
return nil
return nil
} ,
} ,
}
}
@ -97,11 +97,10 @@ var helpSubcommand = Command{
Action : func ( c * Context ) error {
Action : func ( c * Context ) error {
args := c . Args ( )
args := c . Args ( )
if args . Present ( ) {
if args . Present ( ) {
ShowCommandHelp ( c , args . First ( ) )
return ShowCommandHelp ( c , args . First ( ) )
} else {
ShowSubcommandHelp ( c )
}
}
return nil
return ShowSubcommandHelp ( c )
} ,
} ,
}
}
@ -127,30 +126,31 @@ func DefaultAppComplete(c *Context) {
}
}
// Prints help for the given command
// Prints help for the given command
func ShowCommandHelp ( ctx * Context , command string ) {
func ShowCommandHelp ( ctx * Context , command string ) error {
// show the subcommand help for a command with subcommands
// show the subcommand help for a command with subcommands
if command == "" {
if command == "" {
HelpPrinter ( ctx . App . Writer , SubcommandHelpTemplate , ctx . App )
HelpPrinter ( ctx . App . Writer , SubcommandHelpTemplate , ctx . App )
return
return nil
}
}
for _ , c := range ctx . App . Commands {
for _ , c := range ctx . App . Commands {
if c . HasName ( command ) {
if c . HasName ( command ) {
HelpPrinter ( ctx . App . Writer , CommandHelpTemplate , c )
HelpPrinter ( ctx . App . Writer , CommandHelpTemplate , c )
return
return nil
}
}
}
}
if ctx . App . CommandNotFound != nil {
if ctx . App . CommandNotFound == nil {
ctx . App . CommandNotFound ( ctx , command )
return NewExitError ( fmt . Sprintf ( "No help topic for '%v'" , command ) , 3 )
} else {
fmt . Fprintf ( ctx . App . Writer , "No help topic for '%v'\n" , command )
}
}
ctx . App . CommandNotFound ( ctx , command )
return nil
}
}
// Prints help for the given subcommand
// Prints help for the given subcommand
func ShowSubcommandHelp ( c * Context ) {
func ShowSubcommandHelp ( c * Context ) error {
ShowCommandHelp ( c , c . Command . Name )
return ShowCommandHelp ( c , c . Command . Name )
}
}
// Prints the version number of the App
// Prints the version number of the App