Class: ShellOpts::Grammar::OptionGroup
- Defined in:
- lib/shellopts/grammar.rb,
lib/shellopts/renderer.rb,
lib/shellopts/formatter.rb
Overview
Note that all public attributes are assigned by #attach
Constant Summary
Constants inherited from Node
Instance Attribute Summary collapse
-
#brief ⇒ Object
readonly
Brief description of option(s).
-
#description ⇒ Object
readonly
Description of option(s).
-
#options ⇒ Object
readonly
Array of options in declaration order.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(parent, token) ⇒ OptionGroup
constructor
A new instance of OptionGroup.
-
#name ⇒ Object
Duck typing for compatibility with IdrNode (TODO: maybe just make OptionGroup an IdrNode and be over with it).
- #puts_descr ⇒ Object
-
#render(format) ⇒ Object
Formats: :enum -a, –all -r, –recursive :long –all –recursive :short -a -r :multi -a, –all -r, –recursive.
Methods inherited from Node
#analyzer_error, #ancestors, #dump_ast, #dump_attrs, #dump_idr, #inspect, #parents, #parse, parse, #parser_error, #puts_help, #puts_usage, #remove_arg_descr_nodes, #remove_arg_spec_nodes, #remove_brief_nodes, #traverse
Constructor Details
#initialize(parent, token) ⇒ OptionGroup
Returns a new instance of OptionGroup.
176 177 178 179 180 181 182 |
# File 'lib/shellopts/grammar.rb', line 176 def initialize(parent, token) @options = [] @brief = nil @default_brief = nil @description = [] super(parent, token) end |
Instance Attribute Details
#brief ⇒ Object (readonly)
Brief description of option(s)
171 172 173 |
# File 'lib/shellopts/grammar.rb', line 171 def brief @brief end |
#description ⇒ Object (readonly)
Description of option(s)
174 175 176 |
# File 'lib/shellopts/grammar.rb', line 174 def description @description end |
#options ⇒ Object (readonly)
Array of options in declaration order
168 169 170 |
# File 'lib/shellopts/grammar.rb', line 168 def @options end |
Instance Method Details
#name ⇒ Object
Duck typing for compatibility with IdrNode (TODO: maybe just make OptionGroup an IdrNode and be over with it)
165 |
# File 'lib/shellopts/grammar.rb', line 165 def name() .first&.name end |
#puts_descr ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/shellopts/formatter.rb', line 14 def puts_descr puts Ansi.bold(render(:multi)) indent { if description.any? description.each { |descr| descr.puts_descr puts if descr != description.last } elsif brief brief.puts_descr end } end |
#render(format) ⇒ Object
Formats:
:enum -a, --all -r, --recursive
:long --all --recursive
:short -a -r
:multi -a, --all
-r, --recursive
66 67 68 69 70 71 72 73 |
# File 'lib/shellopts/renderer.rb', line 66 def render(format) constrain format, :enum, :long, :short, :multi if format == :multi .map { |option| option.render(:enum) }.join("\n") else .map { |option| option.render(format) }.join(" ") end end |