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.



10
11
12
13
# File 'lib/stacked_config/layers/command_line_layer.rb', line 10

def initialize
  @slop_definition = Slop.new
  build_command_line_options
end

Instance Attribute Details

#extra_helpObject

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_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:



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_parametersObject



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

#helpString

Returns The formatted command line help.

Returns:

  • (String)

    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.banner = build_banner
  self.replace slop_definition.to_hash.delete_if {|k,v| v.nil?}
end

#possible_optionsObject



21
22
23
# File 'lib/stacked_config/layers/command_line_layer.rb', line 21

def possible_options
  slop_definition.to_hash.keys.sort
end

#reloadObject



25
26
27
# File 'lib/stacked_config/layers/command_line_layer.rb', line 25

def reload
  load
end