class StackedConfig::Layers::CommandLineLayer
Attributes
extra_help[RW]
slop_definition[R]
Public Class Methods
new()
click to toggle source
# File lib/stacked_config/layers/command_line_layer.rb, line 10 def initialize @slop_definition = Slop.new build_command_line_options end
Public Instance Methods
add_command_line_section(title) { |slop_definition| ... }
click to toggle source
Yields a slop definition to modify the command line parameters
# 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()
click to toggle source
# 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()
click to toggle source
@return [String] The formatted command line help
# File lib/stacked_config/layers/command_line_layer.rb, line 38 def help slop_definition.to_s end
load(*args)
click to toggle source
# 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_options()
click to toggle source
# File lib/stacked_config/layers/command_line_layer.rb, line 21 def possible_options slop_definition.to_hash.keys.sort end
reload()
click to toggle source
# File lib/stacked_config/layers/command_line_layer.rb, line 25 def reload load end
Private Instance Methods
build_command_line_options()
click to toggle source
Builds common used command line options
# File lib/stacked_config/layers/command_line_layer.rb, line 58 def build_command_line_options add_command_line_section('Generic options') do |slop| slop.on :auto, 'Auto mode. Bypasses questions to user.', :argument => false slop.on :simulate, 'Do not perform the actual underlying actions.', :argument => false slop.on :v, :verbose, 'Enable verbose mode.', :argument => false slop.on :h, :help, 'Displays this help.', :argument => false end end
build_separator(title, width = 80, filler = '-')
click to toggle source
Builds a nice separator
# File lib/stacked_config/layers/command_line_layer.rb, line 53 def build_separator(title, width = 80, filler = '-') "#{filler * 2} #{title} ".ljust width, filler end