wycats-thor 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/thor.rb CHANGED
@@ -22,6 +22,14 @@ class Thor
22
22
  @usage, @desc = usage, description
23
23
  end
24
24
 
25
+ def self.group(name)
26
+ @group_name = name.to_s
27
+ end
28
+
29
+ def self.group_name
30
+ @group_name || 'standard'
31
+ end
32
+
25
33
  def self.method_options(opts)
26
34
  @method_options = opts
27
35
  end
@@ -80,7 +88,7 @@ class Thor
80
88
 
81
89
  def method_added(meth)
82
90
  meth = meth.to_s
83
-
91
+
84
92
  if meth == "initialize"
85
93
  @opts = @method_options
86
94
  @method_options = nil
@@ -90,7 +98,12 @@ class Thor
90
98
  return if !public_instance_methods.include?(meth) || !@usage
91
99
  register_klass_file self
92
100
 
93
- tasks[meth] = Task.new(meth, @desc, @usage, @method_options)
101
+ if !self.opts.empty? || @method_options
102
+ task_options = self.opts.merge(@method_options || {})
103
+ else
104
+ task_options = nil
105
+ end
106
+ tasks[meth] = Task.new(meth, @desc, @usage, task_options)
94
107
 
95
108
  @usage, @desc, @method_options = nil
96
109
  end
data/lib/thor/options.rb CHANGED
@@ -167,7 +167,7 @@ class Thor
167
167
  else
168
168
  sample = @defaults[undasherize(opt)]
169
169
  sample ||= case type
170
- when :optional then opt.gsub(/\-/, "").upcase
170
+ when :optional then undasherize(opt).gsub(/\-/, "_").upcase
171
171
  when :numeric then "N"
172
172
  end
173
173
  "[" + opt + "=" + sample.to_s + "]"
data/lib/thor/runner.rb CHANGED
@@ -113,14 +113,20 @@ class Thor::Runner < Thor
113
113
  end
114
114
 
115
115
  desc "list [SEARCH]", "list the available thor tasks (--substring means SEARCH can be anywhere in the module)"
116
- method_options :substring => :boolean
116
+ method_options :substring => :boolean,
117
+ :group => :optional,
118
+ :all => :boolean
117
119
  def list(search = "")
118
120
  initialize_thorfiles
119
121
  search = ".*#{search}" if options["substring"]
120
122
  search = /^#{search}.*/i
123
+ group = options[:group] || 'standard'
121
124
 
122
- display_klasses(false, Thor.subclasses.select {|k|
123
- Thor::Util.constant_to_thor_path(k.name) =~ search})
125
+ classes = Thor.subclasses.select do |k|
126
+ (options[:all] || k.group_name == group) &&
127
+ Thor::Util.constant_to_thor_path(k.name) =~ search
128
+ end
129
+ display_klasses(false, classes)
124
130
  end
125
131
 
126
132
  # Override Thor#help so we can give info about not-yet-loaded tasks
@@ -176,7 +182,7 @@ class Thor::Runner < Thor
176
182
  raise Error, "No Thor tasks available" if klasses.empty?
177
183
 
178
184
  if with_modules && !(yaml = thor_yaml).empty?
179
- max_name = yaml.max {|(xk,xv),(yk,yv)| xk.size <=> yk.size }.first.size
185
+ max_name = yaml.max {|(xk,xv),(yk,yv)| xk.to_s.size <=> yk.to_s.size }.first.size
180
186
  modules_label = "Modules"
181
187
  namespaces_label = "Namespaces"
182
188
  column_width = [max_name + 4, modules_label.size + 1].max
data/lib/thor/util.rb CHANGED
@@ -1,5 +1,19 @@
1
1
  require 'thor/error'
2
2
 
3
+ module ObjectSpace
4
+
5
+ class << self
6
+
7
+ # @return <Array[Class]> All the classes in the object space.
8
+ def classes
9
+ klasses = []
10
+ ObjectSpace.each_object(Class) {|o| klasses << o}
11
+ klasses
12
+ end
13
+ end
14
+
15
+ end
16
+
3
17
  class Thor
4
18
  module Util
5
19
 
@@ -22,11 +36,11 @@ class Thor
22
36
  end
23
37
 
24
38
  def self.constants_in_contents(str)
25
- klasses = self.constants.dup
26
- eval(str)
27
- ret = self.constants - klasses
28
- ret.each {|k| self.send(:remove_const, k)}
29
- ret
39
+ klasses = ObjectSpace.classes.dup
40
+ Module.new.class_eval(str)
41
+ klasses = ObjectSpace.classes - klasses
42
+ klasses = klasses.select {|k| k < Thor }
43
+ klasses.map! {|k| k.to_s.gsub(/#<Module:\w+>::/, '')}
30
44
  end
31
45
 
32
46
  def self.make_constant(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wycats-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz