lib/gator/command.rb in gator-0.0.19.pre vs lib/gator/command.rb in gator-0.0.20.pre
- old
+ new
@@ -26,10 +26,15 @@
def get_subcommand(*args)
nil
end
+ def resolve_subcommand(command,fallback=nil)
+ return nil unless parent
+ parent.resolve_subcommand(command,fallback)
+ end
+
end
module ActAsCommandCollection
def self.included(base)
@@ -49,16 +54,31 @@
subcommand_classes[d[:command]] = klass
klass.parent_command = self
end
def get_subcommand(*args)
- arg = args.shift
- klass = subcommand_classes[arg.to_s]
- until args.empty? do
- arg = args.shift
+ klass = self
+ args.each do |arg|
+ return nil unless klass.subcommand_classes.has_key? arg
klass = klass.subcommand_classes[arg]
end
klass
+ end
+
+ def resolve_subcommand(command,fallback=nil)
+
+ parent_klass = self
+ klass = parent_klass.get_subcommand *command
+
+ return klass unless klass.nil?
+
+ while parent_klass.parent
+ parent_klass = parent_klass.parent
+ klass = parent_klass.get_subcommand *command
+ return klass unless klass.nil?
+ end
+
+ resolve_subcommand fallback if fallback
end
end
end
\ No newline at end of file