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:.
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.
177 178 179 180 181 182 183 |
# File 'lib/shellopts/grammar.rb', line 177 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)
172 173 174 |
# File 'lib/shellopts/grammar.rb', line 172 def brief @brief end |
#description ⇒ Object (readonly)
Description of option(s)
175 176 177 |
# File 'lib/shellopts/grammar.rb', line 175 def description @description end |
#options ⇒ Object (readonly)
Array of options in declaration order
169 170 171 |
# File 'lib/shellopts/grammar.rb', line 169 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)
166 |
# File 'lib/shellopts/grammar.rb', line 166 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
73 74 75 76 77 78 79 80 |
# File 'lib/shellopts/renderer.rb', line 73 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 |