require 'thor' require 'find' require 'ro_core_ext/string' require "ro_core_ext/hash" require "ro_core_ext/thor" require "ro_core_ext/array" require "ro_helpers/out" require "ro_helpers/bash" require 'active_support/core_ext' require File.expand_path('../../../config/rorc', __FILE__) #Thor.class_eval do # # def self.desc(usage, description, options={}) # if options[:for] # command = find_and_refresh_command(options[:for]) # command.usage = usage if usage # command.description = description if description # else # @usage, @desc, @hide = "#{$ro_commands_argument} #{usage}", description, options[:hide] || false # end # end #end module RoCommands class Base < Thor include Thor::Actions include ::Bash protected def introduction "pending" end def reset instance_variables.each do |iv| instance_variable_set :"iv", nil end end def ro_templates(from, *args, &blk) template("#{from}.tt", *args, &blk) end alias_method :rott, :ro_templates class << self def inherited(sub) sub.class_eval do class << self def get_source_root file_path = ::File.join(RoCommands.lib, name.split("::").map(&:uncamelize).join("/")) dir_path = ::File.dirname file_path template_path = File.join(dir_path, "templates") end end source_root(get_source_root) end end def start(given_args=ARGV, config={}) given_args.flatten! opt = given_args.extract_options! if opt and opt[:pwd] Dir.chdir opt[:pwd] Out.out("Current working path is #{opt[:pwd]}") end given_args = given_args - [{pwd: opt[:pwd]}] super end def method_added(method) super unless method.match(%r{drb_}) meths << method end end def meths @meths.flatten! if @meths.respond_to?(:flatten!) @meths.uniq! if @meths.respond_to?(:uniq!) @meths ||= [] end def usage(meth_name) "#{name.split("::")[-1].uncamelize} #{meth_name}" end def describe(action, item, shortcut_item) "#{action} #{item}" end end def parse_options(options, dict) options.map do |k, v| options[k] = dict[v.to_sym] || v end options end def implicit(keyword) /^#{keyword.split("").join(".*")}.*/ end def find(path) Find.find(path).select { |f| test(?f, f) } end def to_boolean(str) str == "true" end def convert_options(options) opts = {} r = options.split(":") opts[:"#{r[0]}"] = to_boolean r[1] opts end end end