module SanUltari::CommandDescriptor::ClassMethods
Public Instance Methods
available_commands()
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 51 def available_commands @registry.keys end
default(command)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 43 def default command @default_command = command.to_sym end
desc(command, description)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 16 def desc command, description end
get(command)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 47 def get command @registry[command.to_sym] end
group(group_name, clazz, operation = nil)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 40 def group group_name, clazz, operation = nil end
import(clazz, operation = nil)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 26 def import clazz, operation = nil targets = operation targets ||= clazz.available_commands unless targets.kind_of? Array targets = [targets] end targets.each do |cmd| command = cmd.to_sym wrapper = clazz.get command @registry[command] = wrapper end end
list()
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 55 def list end
map(command, clazz, options = nil)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 11 def map command, clazz, options = nil @registry ||= {} @registry[command.to_sym] = SanUltari::CommandWrapper.new command, clazz, nil, options end
option(command, option, options = nil)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 23 def option command, option, options = nil end
param(command, param, options = nil)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 19 def param command, param, options = nil @registry[command.to_sym].add_param param, options end
run(argv)
click to toggle source
# File lib/sanultari/command_descriptor.rb, line 59 def run argv selected_command = nil options = [] args = [] argument_list = argv.clone argv.each do |arg| if arg.start_with? '-' value = argument_list.shift args.push value options.push value next end unless @registry.include? arg.to_sym args.push argument_list.shift next end selected_command = @registry[argument_list.shift.to_sym] end args += argument_list if selected_command == nil options.clear else args -= options end selected_command ||= @registry[@default_command] unless @default_command == nil selected_command.run(args, options) if selected_command != nil end