lib/miu.rb in miu-0.0.2 vs lib/miu.rb in miu-0.0.3

- old
+ new

@@ -1,48 +1,33 @@ require 'miu/version' module Miu - autoload :CLI, 'miu/cli' - class << self def root - require 'pathname' - Pathname.new(File.expand_path('../../', __FILE__)) + @root ||= find_root 'Gemfile' end def plugins @plugins ||= {} end - def register(name, type, options = {}, &block) + def register(name, plugin, options = {}, &block) name = name.to_s usage = options[:usage] || "#{name} [COMMAND]" - desc = options[:desc] || type.to_s + desc = options[:desc] || plugin.to_s - plugins[name] = type - Miu::CLI.register generate_subcommand(name, &block), name, usage, desc if block + plugins[name] = plugin + Miu::CLI.register generate_subcommand(name, plugin, &block), name, usage, desc if block end - private - - def generate_subcommand(name, &block) - require 'thor' - Class.new ::Thor do - include ::Thor::Actions - add_runtime_options! - - class << self - def source_root - Miu.root.to_s - end - - def banner(task, namespace = nil, subcommand = true) - super - end - end - - namespace name - class_eval &block if block + def find_root(flag, base = nil) + require 'pathname' + path = base || Dir.pwd + while path && File.directory?(path) && File.exist?("#{path}/#{flag}") + parent = File.dirname path + path = path != parent && path end + raise 'Could not find root path' unless path + Pathname.new File.realpath(path) end end end