lib/ro_commands/base.rb in ro_commands-0.0.3 vs lib/ro_commands/base.rb in ro_commands-0.0.4

- old
+ new

@@ -1,15 +1,19 @@ require 'thor' require 'find' -require "ro_commands/core_ext/string" -require "ro_commands/core_ext/hash" -require "ro_commands/helpers/out" -require "ro_commands/helpers/bash" -require "active_support/all" -require "ro_commands/core_ext/thor" +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]) @@ -21,18 +25,54 @@ # 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] - Out.out("Current working path is #{opt[:pwd]}") Dir.chdir opt[:pwd] + Out.out("Current working path is #{opt[:pwd]}") end given_args = given_args - [{pwd: opt[:pwd]}] super end @@ -56,28 +96,16 @@ def describe(action, item, shortcut_item) "#{action} #{item}" end end - include ::Bash - def get_options(args) - h = {} - args.select do |a| - a.match ":" - end.each do |a| - r = a.chomp.match(%r{^(\w+)\:(\w+)$}) - if r && r[1] && r[2] - h[r[1].to_sym] = r[2] - end - end - h - end + def parse_options(options, dict) options.map do |k, v| - options[k] = dict[v.to_sym] + options[k] = dict[v.to_sym] || v end options end def implicit(keyword) @@ -95,12 +123,8 @@ def convert_options(options) opts = {} r = options.split(":") opts[:"#{r[0]}"] = to_boolean r[1] opts - end - - def handle_drb_out - Out.msgs end end end