Class: CommandoOpt

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptroute/commando.rb

Overview

base class of command options. all options must have tags and a helpful description… or at least a description.

Direct Known Subclasses

CommandoClosure, CommandoVar

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/scriptroute/commando.rb', line 4

def description
  @description
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/scriptroute/commando.rb', line 4

def tags
  @tags
end

Instance Method Details

#helpString

Returns the help text for this option, comprising tags, default, and description.

Returns:

  • (String)

    the help text for this option, comprising tags, default, and description



17
18
19
20
21
# File 'lib/scriptroute/commando.rb', line 17

def help
  " %20s %4s %-72s" % [ tags.join(", "), 
    self.string_default, 
    @description ]
end

#seek(argv) ⇒ Object

Note:

Modifies argument (removing parsed options)

Parameters:

  • argv (Array<String>)

    the arguments to parse.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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