Sha256: 047b6822ec1b3aac37580e8f49d34f2e3bc113b8e81b489d380229a58775dae6
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
# encoding: utf-8 # require 'kde-build/command' module BuildTool # 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. class HelpCommand < Command 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 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 def usage "Usage: #{commandparser.program_name} help [COMMAND SUBCOMMAND ...]" end 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 ####### private ####### def show_program_help puts commandparser.banner + "\n" if commandparser.banner puts "Usage: #{commandparser.program_name} [options] COMMAND [options] [COMMAND [options] ...] [args]" puts "" list_commands( 1, commandparser.main_command ) puts "" puts commandparser.main_command.options.summarize puts end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
build-tool-0.0.3 | lib/kde-build/command/help.rb |
build-tool-0.0.2 | lib/kde-build/command/help.rb |
build-tool-0.0.1 | lib/kde-build/command/help.rb |