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.
- #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
163 164 165 166 167 168 169 |
# File 'lib/shellopts/grammar.rb', line 163 def initialize(parent, token) = [] @brief = nil @default_brief = nil @description = [] super(parent, token) end |
Instance Attribute Details
#brief ⇒ Object (readonly)
Brief description of option(s)
158 159 160 |
# File 'lib/shellopts/grammar.rb', line 158 def brief @brief end |
#description ⇒ Object (readonly)
Description of option(s)
161 162 163 |
# File 'lib/shellopts/grammar.rb', line 161 def description @description end |
#options ⇒ Object (readonly)
Array of options in declaration order
155 156 157 |
# File 'lib/shellopts/grammar.rb', line 155 def end |
Instance Method Details
#puts_descr ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/shellopts/formatter.rb', line 21 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
60 61 62 63 64 65 66 67 |
# File 'lib/shellopts/renderer.rb', line 60 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 |