lib/gli.rb in davetron5000-gli-0.2.1 vs lib/gli.rb in davetron5000-gli-0.2.3
- old
+ new
@@ -1,9 +1,10 @@
require 'gli/command_line_token.rb'
require 'gli/command.rb'
require 'gli/switch.rb'
require 'gli/flag.rb'
+require 'gli/options.rb'
require 'support/help.rb'
require 'support/rdoc.rb'
# A means to define and parse a command line interface that works as
# Git's does, in that you specify global options, a command name, command
@@ -38,26 +39,26 @@
def arg_name(name); @@next_arg_name = name; end
# set the default value of the next flag
def default_value(val); @@next_default_value = val; end
# Create a flag, which is a switch that takes an argument
- def flag(names)
- flag = Flag.new(names,@@next_desc,@@next_arg_name,@@next_default_value,@@next_long_desc)
+ def flag(*names)
+ flag = Flag.new([names].flatten,@@next_desc,@@next_arg_name,@@next_default_value,@@next_long_desc)
flags[flag.name] = flag
clear_nexts
end
# Create a switch
- def switch(names)
- switch = Switch.new(names,@@next_desc,@@next_long_desc)
+ def switch(*names)
+ switch = Switch.new([names].flatten,@@next_desc,@@next_long_desc)
switches[switch.name] = switch
clear_nexts
end
# Define a command.
- def command(names)
- command = Command.new(names,@@next_desc,@@next_arg_name,@@next_long_desc)
+ def command(*names)
+ command = Command.new([names].flatten,@@next_desc,@@next_arg_name,@@next_long_desc)
commands[command.name] = command
yield command
clear_nexts
end
@@ -121,10 +122,10 @@
# * global options (as a Hash)
# * Command
# * command options (as a Hash)
# * arguments (as an Array)
def parse_options(args)
- global_options,command,options,arguments = parse_options_helper(args.clone,Hash.new,nil,Hash.new,Array.new)
+ global_options,command,options,arguments = parse_options_helper(args.clone,Options.new,nil,Options.new,Array.new)
flags.each { |name,flag| global_options[name] = flag.default_value if !global_options[name] }
command.flags.each { |name,flag| options[name] = flag.default_value if !options[name] }
return [global_options,command,options,arguments]
end