Class: StackedConfig::Layers::CommandLineLayer

Inherits:
SuperStack::Layer
  • Object
show all
Defined in:
lib/stacked_config/layers/command_line_layer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandLineLayer

Returns a new instance of CommandLineLayer.



8
9
10
11
# File 'lib/stacked_config/layers/command_line_layer.rb', line 8

def initialize
  @slop_definition = Slop.new
  build_command_line_options
end

Instance Attribute Details

#slop_definitionObject (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

Yields:



28
29
30
31
32
33
# File 'lib/stacked_config/layers/command_line_layer.rb', line 28

def add_command_line_section(title)
  raise 'Incorrect usage' unless block_given?
  slop_definition.separator build_separator(title)
  yield slop_definition
  reload
end

#helpString

Returns The formatted command line help.

Returns:

  • (String)

    The formatted command line help



36
37
38
# File 'lib/stacked_config/layers/command_line_layer.rb', line 36

def help
  slop_definition.to_s
end

#load(*args) ⇒ Object



13
14
15
16
17
# File 'lib/stacked_config/layers/command_line_layer.rb', line 13

def load(*args)
  slop_definition.parse
  slop_definition.banner = build_banner
  replace slop_definition.to_hash.delete_if {|k,v| v.nil?}
end

#possible_optionsObject



19
20
21
# File 'lib/stacked_config/layers/command_line_layer.rb', line 19

def possible_options
  slop_definition.to_hash.keys.sort
end

#reloadObject



23
24
25
# File 'lib/stacked_config/layers/command_line_layer.rb', line 23

def reload
  load
end