thor 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,19 @@
5
5
  * Improve help output to list shorthand switches, too
6
6
  * Investigate and fix deep namespacing ("foo:bar:baz") issues
7
7
 
8
+ == 0.9.7, released 2008-10-13
9
+
10
+ * Setting global method options on the initialize method works as expected:
11
+ All other tasks will accept these global options in addition to their own.
12
+ * Added 'group' notion to Thor task sets (class Thor); by default all tasks
13
+ are in the 'standard' group. Running 'thor -T' will only show the standard
14
+ tasks - adding --all will show all tasks. You can also filter on a specific
15
+ group using the --group option: thor -T --group advanced
16
+
17
+ == 0.9.6, released 2008-09-13
18
+
19
+ * Generic improvements
20
+
8
21
  == 0.9.5, released 2008-08-27
9
22
 
10
23
  * Improve Windows compatibility
@@ -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
@@ -65,6 +65,8 @@ class Thor
65
65
  def initialize(switches)
66
66
  @defaults = {}
67
67
  @shorts = {}
68
+
69
+ @leading_non_opts, @trailing_non_opts = [], []
68
70
 
69
71
  @switches = switches.inject({}) do |mem, (name, type)|
70
72
  if name.is_a?(Array)
@@ -167,13 +169,15 @@ class Thor
167
169
  else
168
170
  sample = @defaults[undasherize(opt)]
169
171
  sample ||= case type
170
- when :optional then opt.gsub(/\-/, "").upcase
172
+ when :optional then undasherize(opt).gsub(/\-/, "_").upcase
171
173
  when :numeric then "N"
172
174
  end
173
175
  "[" + opt + "=" + sample.to_s + "]"
174
176
  end
175
177
  end.join(" ")
176
178
  end
179
+
180
+ alias :to_s :formatted_usage
177
181
 
178
182
  private
179
183
 
@@ -92,7 +92,7 @@ class Thor::Runner < Thor
92
92
 
93
93
  puts "Updating `#{name}' from #{yaml[name][:location]}"
94
94
  old_filename = yaml[name][:filename]
95
- options["as"] = name
95
+ self.options = self.options.merge("as" => name)
96
96
  filename = install(yaml[name][:location])
97
97
  unless filename == old_filename
98
98
  File.delete(File.join(thor_root, old_filename))
@@ -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
@@ -194,9 +200,6 @@ class Thor::Runner < Thor
194
200
  puts
195
201
  end
196
202
 
197
- puts "Tasks"
198
- puts "-----"
199
-
200
203
  # Calculate the largest base class name
201
204
  max_base = klasses.max do |x,y|
202
205
  Thor::Util.constant_to_thor_path(x.name).size <=> Thor::Util.constant_to_thor_path(y.name).size
@@ -208,16 +211,39 @@ class Thor::Runner < Thor
208
211
  end
209
212
 
210
213
  max_left = max_left_item.maxima.usage + max_left_item.maxima.opt
211
-
212
- klasses.each {|k| display_tasks(k, max_base, max_left)}
214
+
215
+ unless klasses.empty?
216
+ puts # add some spacing
217
+ klasses.each { |k| display_tasks(k, max_base, max_left); }
218
+ else
219
+ puts "\033[1;34mNo Thor tasks available\033[0m"
220
+ end
213
221
  end
214
222
 
215
223
  def display_tasks(klass, max_base, max_left)
216
- base = Thor::Util.constant_to_thor_path(klass.name)
217
- klass.tasks.each true do |name, task|
218
- format_string = "%-#{max_left + max_base + 5}s"
219
- print format_string % task.formatted_usage(true)
220
- puts task.description
224
+ if klass.tasks.values.length > 1
225
+
226
+ base = Thor::Util.constant_to_thor_path(klass.name)
227
+
228
+ if base.to_a.empty?
229
+ base = 'default'
230
+ puts "\033[1;35m#{base}\033[0m"
231
+ else
232
+ puts "\033[1;34m#{base}\033[0m"
233
+ end
234
+ puts "-" * base.length
235
+
236
+ klass.tasks.each true do |name, task|
237
+ format_string = "%-#{max_left + max_base + 5}s"
238
+ print format_string % task.formatted_usage(true)
239
+ puts task.description
240
+ end
241
+
242
+ unless klass.opts.empty?
243
+ puts "\nglobal options: #{Options.new(klass.opts)}"
244
+ end
245
+
246
+ puts # add some spacing
221
247
  end
222
248
  end
223
249
 
@@ -3,9 +3,16 @@ require 'thor/util'
3
3
 
4
4
  class Thor
5
5
  class Task < Struct.new(:meth, :description, :usage, :opts, :klass)
6
+
6
7
  def self.dynamic(meth, klass)
7
8
  new(meth, "A dynamically-generated task", meth.to_s, nil, klass)
8
9
  end
10
+
11
+ def initialize(*args)
12
+ # keep the original opts - we need them later on
13
+ @options = args[3] || {}
14
+ super
15
+ end
9
16
 
10
17
  def parse(obj, args)
11
18
  list, hash = parse_args(args)
@@ -48,7 +55,15 @@ class Thor
48
55
 
49
56
  def opts
50
57
  return super unless super.kind_of? Hash
51
- self.opts = Options.new(super)
58
+ @_opts ||= Options.new(super)
59
+ end
60
+
61
+ def full_opts
62
+ @_full_opts ||= Options.new((klass.opts || {}).merge(@options))
63
+ end
64
+
65
+ def options?
66
+ @options.kind_of?(Hash)
52
67
  end
53
68
 
54
69
  def formatted_usage(namespace = false)
@@ -59,9 +74,9 @@ class Thor
59
74
  protected
60
75
 
61
76
  def parse_args(args)
62
- return [args, {}] unless opts
63
- hash = opts.parse(args)
64
- list = opts.non_opts
77
+ return [args, {}] unless options?
78
+ hash = full_opts.parse(args)
79
+ list = full_opts.non_opts
65
80
  [list, hash]
66
81
  end
67
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-12 00:00:00 -07:00
12
+ date: 2008-10-13 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements: []
66
66
 
67
67
  rubyforge_project: thor
68
- rubygems_version: 1.2.0
68
+ rubygems_version: 1.3.0
69
69
  signing_key:
70
70
  specification_version: 2
71
71
  summary: A gem that maps options to a class