class Convoy::Setup::Configuration::Generator
Attributes
setup[R]
Public Class Methods
new(setup)
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 7 def initialize(setup) @setup = setup end
Public Instance Methods
default_data()
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 11 def default_data config_hash = init_config_hash options([], config_hash[:global][:options]) #global options options_for_commands(setup.canonical_command_names_for([]), [], config_hash[:global][:commands]) config_hash end
Private Instance Methods
add_setup_options_to(parser, context = [])
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 57 def add_setup_options_to(parser, context = []) setup.options_for(context).each do |name, opts| parser.opt name, opts[:desc] || "", opts.dup #have to make sure to dup here, otherwise opts might get stuff added to it and it #may cause problems later, e.g. adds default value and when parsed again trollop barfs end parser end
default_option_values(parser)
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 65 def default_option_values(parser) hash = {} parser.specs.each_pair do |key, data| hash[key] = data[:default] || nil end hash end
init_config_hash()
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 34 def init_config_hash { :global => { :options => {}, :commands => {} }, :user => {} } end
init_parser(stop_words)
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 51 def init_parser(stop_words) Trollop::Parser.new.tap do |parser| parser.stop_on(stop_words) # make sure we halt parsing if we see a command end end
options(context = [], options = {})
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 44 def options(context = [], options = {}) command_names = setup.command_names_for(context) parser = init_parser(command_names) parser = add_setup_options_to(parser, context) options.merge!(default_option_values(parser)) end
options_for_commands(commands, context, options = {})
click to toggle source
# File lib/convoy/setup/configuration/generator.rb, line 20 def options_for_commands(commands, context, options = {}) commands.each do |command_name| command_name = command_name.to_sym #next if command_name == :convoy options[command_name] = {} options[command_name][:options] = {} options[command_name][:commands] = {} current_context = context.dup current_context << command_name options(current_context, options[command_name][:options]) #command_options options_for_commands(setup.canonical_command_names_for(current_context), current_context, options[command_name][:commands]) end end