lib/gli.rb in davetron5000-gli-0.2.0 vs lib/gli.rb in davetron5000-gli-0.2.1

- old
+ new

@@ -1,18 +1,19 @@ require 'gli/command_line_token.rb' require 'gli/command.rb' require 'gli/switch.rb' require 'gli/flag.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 # specific options, and then command arguments. module GLI extend self - VERSION = '0.1.5' + VERSION = '0.2.1' @@program_name = $0.split(/\//)[-1] @@post_block = nil @@pre_block = nil @@error_block = nil @@ -23,34 +24,40 @@ flags.clear commands.clear clear_nexts end - # describe the next switch, flag, or command + # describe the next switch, flag, or command. This should be a + # short, one-line description def desc(description); @@next_desc = description; end + + # Provide a longer, more detailed description. This + # will be reformatted and wrapped to fit in 80 columns + def long_desc(long_desc); @@next_long_desc = long_desc; end + # describe the argument name of the next flag 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) + flag = Flag.new(names,@@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) + switch = Switch.new(names,@@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) + command = Command.new(names,@@next_desc,@@next_arg_name,@@next_long_desc) commands[command.name] = command yield command clear_nexts end @@ -79,11 +86,13 @@ @@error_block = a_proc end # Runs whatever command is needed based on the arguments. def run(args) - commands[:help] = DefaultHelpCommand.new if !commands[:help] + rdoc = RDocCommand.new + commands[:rdoc] = rdoc if !commands[:rdoc] + commands[:help] = DefaultHelpCommand.new(rdoc) if !commands[:help] begin global_options,command,options,arguments = parse_options(args) proceed = true proceed = @@pre_block.call(global_options,command,options,arguments) if @@pre_block if proceed @@ -137,9 +146,10 @@ def clear_nexts @@next_desc = nil @@next_arg_name = nil @@next_default_value = nil + @@next_long_desc = nil end clear_nexts def flags; @@flags ||= {}; end