Class: ShellOpts::Grammar::Program
- Defined in:
- lib/shellopts/grammar/program.rb
Overview
Program is the root object of the grammar
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Array of non-option litteral arguments (ie. what comes after the double dash (‘
--’) in the usage definition).
Attributes inherited from Command
#command_list, #commands, #name, #option_list, #options, #parent
Attributes inherited from Node
Instance Method Summary collapse
-
#dump(&block) ⇒ Object
:nocov:.
-
#initialize(name, option_list) ⇒ Program
constructor
Initialize a top-level Program object.
-
#usage ⇒ Object
Usage string to be used in error messages.
Constructor Details
#initialize(name, option_list) ⇒ Program
Initialize a top-level Program object
10 11 12 13 |
# File 'lib/shellopts/grammar/program.rb', line 10 def initialize(name, option_list) super(nil, name, option_list) @args = [] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Array of non-option litteral arguments (ie. what comes after the double dash (‘--’) in the usage definition). Initially empty but filled out during compilation
7 8 9 |
# File 'lib/shellopts/grammar/program.rb', line 7 def args @args end |
Instance Method Details
#dump(&block) ⇒ Object
:nocov:
26 27 28 29 30 31 |
# File 'lib/shellopts/grammar/program.rb', line 26 def dump(&block) super { puts "args: #{args.inspect}" puts "usage: #{usage.inspect}" } end |
#usage ⇒ Object
Usage string to be used in error messages. The string is kept short by only listing the shortest option (if there is more than one)
17 18 19 20 21 22 23 |
# File 'lib/shellopts/grammar/program.rb', line 17 def usage ( (option_list) + commands.values.map { |cmd| render_command(cmd) } + args ).flatten.join(" ") end |