Sha256: 6d5c117932cb9e844c9ba106bb5a290cec9428c88c2d03032b2837e85a0edc81

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

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"

#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
    protected
    class << self

      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

    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]
      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

    def handle_drb_out(result)
      Out.msgs
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ro_commands-0.0.1 lib/ro_commands/base.rb