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:



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

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



45
46
47
48
49
50
# File 'lib/stacked_config/layers/command_line_layer.rb', line 45

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



41
42
43
# File 'lib/stacked_config/layers/command_line_layer.rb', line 41

def help
  slop_definition.to_s
end

#load(*args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/stacked_config/layers/command_line_layer.rb', line 15

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

#possible_optionsObject



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

def possible_options
  slop_definition.to_hash.keys.sort
end

#reloadObject



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

def reload
  load
end