Class: BuildTool::HelpCommand

Inherits:
Command show all
Defined in:
lib/kde-build/command/help.rb

Overview

The default help command. It adds the options “-h” and “–help” to the global options of the associated CommandParser. When the command is specified on the command line, it can show the main help or individual command help.

Instance Method Summary collapse

Methods inherited from Command

#complete, #show_help

Constructor Details

#initializeHelpCommand

Returns a new instance of HelpCommand.



13
14
15
16
17
18
19
# File 'lib/kde-build/command/help.rb', line 13

def initialize
  super( 'help', false )
  self.short_desc = 'Provide help for individual commands'
  self.description = 'This command prints the program help if no arguments are given. ' \
  'If one or more command names are given as arguments, these arguments are interpreted ' \
  'as a hierachy of commands and the help for the right most command is show.'
end

Instance Method Details

#execute(args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kde-build/command/help.rb', line 36

def execute( args )
  if args.length > 0
    cmd = commandparser.main_command
    arg = args.shift
    while !arg.nil? && cmd.commands[ arg ]
      cmd = cmd.commands[arg]
      arg = args.shift
    end
    if arg.nil?
      cmd.show_help
    else
      raise InvalidArgumentError, args.unshift( arg ).join(' ')
    end
  else
    show_program_help
  end
end

#initObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/kde-build/command/help.rb', line 21

def init
  case commandparser.main_command.options
  when CmdParse::OptionParserWrapper
    commandparser.main_command.options.instance do |opt|
      opt.on_tail( "-h", "--help", "Show help" ) do
        execute( [] )
      end
    end
  end
end

#usageObject



32
33
34
# File 'lib/kde-build/command/help.rb', line 32

def usage
  "Usage: #{commandparser.program_name} help [COMMAND SUBCOMMAND ...]"
end