Skip to content

Commit

Permalink
Merge commit 'wycats/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cypher committed May 21, 2008
2 parents e3572ba + 3b64668 commit 571bdfd
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 273 deletions.
238 changes: 0 additions & 238 deletions lib/getopt.rb

This file was deleted.

25 changes: 22 additions & 3 deletions lib/thor.rb
@@ -1,5 +1,5 @@
$:.unshift File.expand_path(File.dirname(__FILE__))
require "getopt"
require "thor/options"
require "thor/util"
require "thor/task"
require "thor/task_hash"
Expand All @@ -22,7 +22,7 @@ def self.desc(usage, description)

def self.method_options(opts)
@method_options = opts.inject({}) do |accum, (k,v)|
accum.merge("--" + k.to_s => v.to_s.upcase)
accum.merge("--" + k.to_s => v.to_sym)
end
end

Expand All @@ -38,6 +38,10 @@ def self.tasks
@tasks ||= TaskHash.new(self)
end

def self.opts
(@opts || {}).merge(self == Thor ? {} : superclass.opts)
end

def self.[](task)
namespaces = task.split(":")
klass = Thor::Util.constant_from_thor_path(namespaces[0...-1].join(":"))
Expand All @@ -55,11 +59,15 @@ def self.maxima
end

def self.start(args = ARGV)
options = Thor::Options.new(args, self.opts)
opts = options.getopts
args = options.args

meth = args.first
meth = @map[meth].to_s if @map && @map[meth]
meth ||= "help"

tasks[meth].parse args[1..-1]
tasks[meth].parse new(opts, *args), args[1..-1]
rescue Thor::Error => e
$stderr.puts e.message
end
Expand All @@ -72,6 +80,13 @@ def inherited(klass)

def method_added(meth)
meth = meth.to_s

if meth == "initialize"
@opts = @method_options
@method_options = nil
return
end

return if !public_instance_methods.include?(meth) || !@usage
register_klass_file self

Expand All @@ -91,6 +106,10 @@ def register_klass_file(klass, file = caller[1].split(":")[0])
subclasses << klass unless subclasses.include?(klass)
end
end

def initialize(opts = {}, *args)
p opts
end

map ["-h", "-?", "--help", "-D"] => :help

Expand Down

0 comments on commit 571bdfd

Please sign in to comment.