Class: StackedConfig::Layers::CommandLineLayer
- Inherits:
-
SuperStack::Layer
- Object
- SuperStack::Layer
- StackedConfig::Layers::CommandLineLayer
- Defined in:
- lib/stacked_config/layers/command_line_layer.rb
Instance Attribute Summary collapse
-
#extra_help ⇒ Object
Returns the value of attribute extra_help.
-
#slop_definition ⇒ Object
readonly
Returns the value of attribute slop_definition.
Instance Method Summary collapse
-
#add_command_line_section(title) {|slop_definition| ... } ⇒ Object
Yields a slop definition to modify the command line parameters.
- #extra_parameters ⇒ Object
-
#help ⇒ String
The formatted command line help.
-
#initialize ⇒ CommandLineLayer
constructor
A new instance of CommandLineLayer.
- #load(*args) ⇒ Object
- #possible_options ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize ⇒ CommandLineLayer
Returns a new instance of CommandLineLayer.
10 11 12 13 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 10 def initialize @slop_definition = Slop.new end |
Instance Attribute Details
#extra_help ⇒ Object
Returns the value of attribute extra_help.
8 9 10 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 8 def extra_help @extra_help end |
#slop_definition ⇒ Object (readonly)
Returns the value of attribute slop_definition.
6 7 8 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 6 def slop_definition @slop_definition end |
Instance Method Details
#add_command_line_section(title) {|slop_definition| ... } ⇒ Object
Yields a slop definition to modify the command line parameters
30 31 32 33 34 35 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 30 def add_command_line_section(title) raise 'Incorrect usage' unless block_given? slop_definition.separator build_separator(title) yield slop_definition reload end |
#extra_parameters ⇒ Object
42 43 44 45 46 47 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 42 def extra_parameters save = ARGV.dup return slop_definition.parse!.dup ensure ARGV.replace save end |
#help ⇒ String
Returns The formatted command line help.
38 39 40 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 38 def help slop_definition.to_s end |
#load(*args) ⇒ Object
15 16 17 18 19 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 15 def load(*args) slop_definition.parse slop_definition. = self.replace slop_definition.to_hash.delete_if {|k,v| v.nil?} end |
#possible_options ⇒ Object
21 22 23 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 21 def slop_definition.to_hash.keys.sort end |
#reload ⇒ Object
25 26 27 |
# File 'lib/stacked_config/layers/command_line_layer.rb', line 25 def reload load end |