Module: UltraCommandLine::Manager::Factory
Instance Method Summary
collapse
#from_yaml, #from_yaml_file
Instance Method Details
#from_hash(definition_hash, factory_options = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/ultra_command_line/manager/factory.rb', line 8
def from_hash(definition_hash, factory_options = {})
UltraCommandLine.logger.debug 'Starting commands analysis from definition hash.'
commands = []
UltraCommandLine.logger.debug 'Defining main command.'
main_command = create_command '', definition_hash
main_command.banner = definition_hash.fetch :banner, ''
commands << main_command
definition_hash.fetch(:subcommands, {}).each do |subcommand_name, subcommand_definition|
UltraCommandLine.logger.debug "Defining sub-command '#{subcommand_name}'."
subcommand = create_command subcommand_name, subcommand_definition
subcommand.banner = subcommand_definition.fetch :banner, ''
main_command.options.select(&:global?).each do |global_option|
subcommand.options << global_option
end
commands << subcommand
end
if block_given?
yield commands
else
new_manager = new commands
new_manager.initialize_definition definition_hash
commands.each {|c| c.send :manager=, new_manager}
new_manager
end
end
|