wycats-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.
data/CHANGELOG.rdoc CHANGED
@@ -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
data/lib/thor/options.rb CHANGED
@@ -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)
@@ -174,6 +176,8 @@ class Thor
174
176
  end
175
177
  end.join(" ")
176
178
  end
179
+
180
+ alias :to_s :formatted_usage
177
181
 
178
182
  private
179
183
 
data/lib/thor/runner.rb CHANGED
@@ -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))
@@ -200,9 +200,6 @@ class Thor::Runner < Thor
200
200
  puts
201
201
  end
202
202
 
203
- puts "Tasks"
204
- puts "-----"
205
-
206
203
  # Calculate the largest base class name
207
204
  max_base = klasses.max do |x,y|
208
205
  Thor::Util.constant_to_thor_path(x.name).size <=> Thor::Util.constant_to_thor_path(y.name).size
@@ -214,16 +211,39 @@ class Thor::Runner < Thor
214
211
  end
215
212
 
216
213
  max_left = max_left_item.maxima.usage + max_left_item.maxima.opt
217
-
218
- 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
219
221
  end
220
222
 
221
223
  def display_tasks(klass, max_base, max_left)
222
- base = Thor::Util.constant_to_thor_path(klass.name)
223
- klass.tasks.each true do |name, task|
224
- format_string = "%-#{max_left + max_base + 5}s"
225
- print format_string % task.formatted_usage(true)
226
- 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
227
247
  end
228
248
  end
229
249
 
data/lib/thor/task.rb CHANGED
@@ -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
data/lib/thor.rb CHANGED
@@ -98,12 +98,7 @@ class Thor
98
98
  return if !public_instance_methods.include?(meth) || !@usage
99
99
  register_klass_file self
100
100
 
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)
101
+ tasks[meth] = Task.new(meth, @desc, @usage, @method_options)
107
102
 
108
103
  @usage, @desc, @method_options = nil
109
104
  end
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.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz