class CommandoOpt
base class of command options. all options must have tags and a helpful description… or at least a description.
Attributes
description[R]
Public Class Methods
new(tags, description)
click to toggle source
# File lib/scriptroute/commando.rb, line 6 def initialize(tags, description) raise ArgumentError, "description must be a string (not #{description.class})" unless(description.is_a?(String)) if(!tags.is_a?(Array)) then tags = [tags] end @tags = tags @description = description end
Public Instance Methods
help()
click to toggle source
@return [String] the help text for this option,
comprising tags, default, and description
# File lib/scriptroute/commando.rb, line 17 def help " %20s %4s %-72s" % [ tags.join(", "), self.string_default, @description ] end
seek(argv)
click to toggle source
@note Modifies argument (removing parsed options) @param [Array<String>] argv the arguments to parse.
# File lib/scriptroute/commando.rb, line 24 def seek(argv) argv.each_with_index { |a,i| tags.each { |t| if(a == t) then argv.delete_at(i) if(takes_argument?) then set(argv[i]) argv.delete_at(i) else set(TRUE) # if closure, then the arg is ignored. end end } } end