Class: Commander
- Inherits:
-
Object
- Object
- Commander
- Defined in:
- lib/commander-tool.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Method Summary collapse
- #add_command(name, description = "", &block) ⇒ Object
- #add_option(switches, description = "") ⇒ Object
-
#initialize ⇒ Commander
constructor
A new instance of Commander.
- #parse(args = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ Commander
Returns a new instance of Commander.
56 57 58 59 |
# File 'lib/commander-tool.rb', line 56 def initialize @commands = {} = [] end |
Instance Method Details
#add_command(name, description = "", &block) ⇒ Object
61 62 63 64 65 |
# File 'lib/commander-tool.rb', line 61 def add_command(name, description = "", &block) command = Command.new(name, description, &block) @commands[command.name] = command command end |
#add_option(switches, description = "") ⇒ Object
67 68 69 70 |
# File 'lib/commander-tool.rb', line 67 def add_option(switches, description = "") << Option.new(switches, description) self end |
#parse(args = ARGV) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/commander-tool.rb', line 72 def parse(args = ARGV) , remaining = ( args, ) command_name = remaining.shift if command_name.nil? handle_no_command() return end command = @commands[command_name] unless command raise_unknown_command(command_name) end parse_command( command, remaining, ) end |