thor 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 0.16.0, release 2012-08-14
2
+ * Add enum to string arguments
3
+
1
4
  == 0.15.4, release 2012-06-29
2
5
  * Fix regression when destination root contains reserved regexp characters
3
6
 
@@ -321,7 +321,7 @@ class Thor
321
321
 
322
322
  # receives a (possibly nil) task name and returns a name that is in
323
323
  # the tasks hash. In addition to normalizing aliases, this logic
324
- # will determine if a shortened command is an unambiguous prefix of
324
+ # will determine if a shortened command is an unambiguous substring of
325
325
  # a task or alias.
326
326
  #
327
327
  # +normalize_task_name+ also converts names like +animal-prison+
@@ -344,7 +344,7 @@ class Thor
344
344
  end
345
345
 
346
346
  # this is the logic that takes the task name passed in by the user
347
- # and determines whether it is an unambiguous prefix of a task or
347
+ # and determines whether it is an unambiguous substrings of a task or
348
348
  # alias name.
349
349
  def find_task_possibilities(meth)
350
350
  len = meth.to_s.length
@@ -508,6 +508,7 @@ class Thor
508
508
 
509
509
  list << item
510
510
  list << [ "", "# Default: #{option.default}" ] if option.show_default?
511
+ list << [ "", "# Possible values: #{option.enum.join(', ')}" ] if option.enum
511
512
  end
512
513
  end
513
514
 
@@ -2,7 +2,7 @@ class Thor
2
2
  class Argument #:nodoc:
3
3
  VALID_TYPES = [ :numeric, :hash, :array, :string ]
4
4
 
5
- attr_reader :name, :description, :required, :type, :default, :banner
5
+ attr_reader :name, :description, :enum, :required, :type, :default, :banner
6
6
  alias :human_name :name
7
7
 
8
8
  def initialize(name, options={})
@@ -19,6 +19,7 @@ class Thor
19
19
  @type = (type || :string).to_sym
20
20
  @default = options[:default]
21
21
  @banner = options[:banner] || default_banner
22
+ @enum = options[:enum]
22
23
 
23
24
  validate! # Trigger specific validations
24
25
  end
@@ -43,7 +44,11 @@ class Thor
43
44
  protected
44
45
 
45
46
  def validate!
46
- raise ArgumentError, "An argument cannot be required and have default value." if required? && !default.nil?
47
+ if required? && !default.nil?
48
+ raise ArgumentError, "An argument cannot be required and have default value."
49
+ elsif @enum && !@enum.is_a?(Array)
50
+ raise ArgumentError, "An argument cannot have an enum other than an array."
51
+ end
47
52
  end
48
53
 
49
54
  def valid_type?(type)
@@ -144,7 +144,13 @@ class Thor
144
144
  if no_or_skip?(name)
145
145
  nil
146
146
  else
147
- shift
147
+ value = shift
148
+ if @switches.is_a?(Hash) && switch = @switches[name]
149
+ if switch.enum && !switch.enum.include?(value)
150
+ raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
151
+ end
152
+ end
153
+ value
148
154
  end
149
155
  end
150
156
 
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.15.4"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -138,6 +138,11 @@ describe Thor::Base do
138
138
  content.should =~ /Foo options\:/
139
139
  content.should =~ /--last-name=LAST_NAME/
140
140
  end
141
+
142
+ it "displays choices for enums" do
143
+ content = capture(:stdout) { Enum.help(Thor::Base.shell.new) }
144
+ content.should =~ /Possible values\: apple, banana/
145
+ end
141
146
  end
142
147
 
143
148
  describe "#namespace" do
@@ -0,0 +1,10 @@
1
+ class Enum < Thor::Group
2
+ include Thor::Actions
3
+
4
+ desc "snack"
5
+ class_option "fruit", :aliases => "-f", :type => :string, :enum => %w(apple banana)
6
+ def snack
7
+ puts options['fruit']
8
+ end
9
+
10
+ end
@@ -25,6 +25,12 @@ describe Thor::Argument do
25
25
  argument(:task, :type => :string, :default => "bar", :required => true)
26
26
  }.should raise_error(ArgumentError, "An argument cannot be required and have default value.")
27
27
  end
28
+
29
+ it "raises an error if enum isn't an array" do
30
+ lambda {
31
+ argument(:task, :type => :string, :enum => "bar")
32
+ }.should raise_error(ArgumentError, "An argument cannot have an enum other than an array.")
33
+ end
28
34
  end
29
35
 
30
36
  describe "#usage" do
@@ -27,6 +27,7 @@ load File.join(File.dirname(__FILE__), "fixtures", "task.thor")
27
27
  load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
28
28
  load File.join(File.dirname(__FILE__), "fixtures", "script.thor")
29
29
  load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor")
30
+ load File.join(File.dirname(__FILE__), "fixtures", "enum.thor")
30
31
 
31
32
  RSpec.configure do |config|
32
33
  config.before do
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
16
16
  s.extra_rdoc_files = ['CHANGELOG.rdoc', 'LICENSE.md', 'README.md', 'Thorfile']
17
17
  s.files = `git ls-files`.split("\n")
18
- s.homepage = 'http://github.com/wycats/thor'
18
+ s.homepage = 'http://whatisthor.com/'
19
19
  s.name = 'thor'
20
20
  s.rdoc_options = ['--charset=UTF-8']
21
21
  s.require_paths = ['lib']
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.15.4
4
+ version: 0.16.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-29 00:00:00.000000000 Z
13
+ date: 2012-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: &2165788460 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '1.0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2165788460
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: fakeweb
28
- requirement: &2165787960 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ~>
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '1.3'
34
39
  type: :development
35
40
  prerelease: false
36
- version_requirements: *2165787960
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rake
39
- requirement: &2165787500 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0.9'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *2165787500
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '0.9'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rdoc
50
- requirement: &2165787040 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '3.9'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *2165787040
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '3.9'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rspec
61
- requirement: &2165802940 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ~>
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '2.3'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *2165802940
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '2.3'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: simplecov
72
- requirement: &2165802480 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ~>
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: '0.4'
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *2165802480
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.4'
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: childlabor
83
- requirement: &2165802100 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ! '>='
@@ -88,7 +118,12 @@ dependencies:
88
118
  version: '0'
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *2165802100
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
92
127
  description: A scripting framework that replaces rake, sake and rubigen
93
128
  email: ruby-thor@googlegroups.com
94
129
  executables:
@@ -164,6 +199,7 @@ files:
164
199
  - spec/fixtures/doc/components/.empty_directory
165
200
  - spec/fixtures/doc/config.rb
166
201
  - spec/fixtures/doc/config.yaml.tt
202
+ - spec/fixtures/enum.thor
167
203
  - spec/fixtures/group.thor
168
204
  - spec/fixtures/invoke.thor
169
205
  - spec/fixtures/path with spaces
@@ -187,7 +223,7 @@ files:
187
223
  - spec/thor_spec.rb
188
224
  - spec/util_spec.rb
189
225
  - thor.gemspec
190
- homepage: http://github.com/wycats/thor
226
+ homepage: http://whatisthor.com/
191
227
  licenses: []
192
228
  post_install_message:
193
229
  rdoc_options:
@@ -208,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
244
  version: 1.3.6
209
245
  requirements: []
210
246
  rubyforge_project:
211
- rubygems_version: 1.8.15
247
+ rubygems_version: 1.8.23
212
248
  signing_key:
213
249
  specification_version: 3
214
250
  summary: A scripting framework that replaces rake, sake and rubigen
@@ -235,6 +271,7 @@ test_files:
235
271
  - spec/fixtures/doc/components/.empty_directory
236
272
  - spec/fixtures/doc/config.rb
237
273
  - spec/fixtures/doc/config.yaml.tt
274
+ - spec/fixtures/enum.thor
238
275
  - spec/fixtures/group.thor
239
276
  - spec/fixtures/invoke.thor
240
277
  - spec/fixtures/path with spaces