module Bundler::Thor::Util
def find_class_and_command_by_namespace(namespace, fallback = true)
namespace
==== Parameters
Bundler::Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
Bundler::Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
Bundler::Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default command
end
class Baz::Foo < Bundler::Thor::Group
end
end
def baz
class Foo::Bar < Bundler::Thor
==== Examples
again. If found, returns the highest entry as the class name.
if it's not found, removes the highest entry and searches for the class
from it. It first searches for a class using the all the given namespace,
Receives a namespace and tries to retrieve a Bundler::Thor or Bundler::Thor::Group class
def find_class_and_command_by_namespace(namespace, fallback = true) if namespace.include?(":") # look for a namespaced command pieces = namespace.split(":") command = pieces.pop klass = Bundler::Thor::Util.find_by_namespace(pieces.join(":")) end unless klass # look for a Bundler::Thor::Group with the right name klass, command = Bundler::Thor::Util.find_by_namespace(namespace), nil end if !klass && fallback # try a command in the default namespace command = namespace klass = Bundler::Thor::Util.find_by_namespace("") end [klass, command] end