slop 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/slop.rb CHANGED
@@ -16,7 +16,7 @@ class Slop
16
16
  class InvalidOptionError < RuntimeError; end
17
17
 
18
18
  # @return [String] The current version string
19
- VERSION = '1.5.1'
19
+ VERSION = '1.5.2'
20
20
 
21
21
  # Parses the items from a CLI format into a friendly object.
22
22
  #
@@ -47,7 +47,12 @@ class Slop
47
47
  # @return [Hash]
48
48
  attr_reader :commands
49
49
 
50
+ # @overload banner=(string)
51
+ # Set the banner
52
+ # @param [String] string The text to set the banner to
50
53
  attr_writer :banner
54
+
55
+ # @return [Integer] The length of the longest flag slop knows of
51
56
  attr_accessor :longest_flag
52
57
 
53
58
  # @param [Hash] options
@@ -179,6 +184,7 @@ class Slop
179
184
  #
180
185
  # # ARGV is `create -v`
181
186
  # opts.commands[:create].verbose? #=> true
187
+ # @since 1.5.0
182
188
  # @return [Slop] a new instance of Slop namespaced to +label+
183
189
  def command(label, options={}, &block)
184
190
  if @commands[label]
@@ -204,6 +210,7 @@ class Slop
204
210
  # Slop.parse do
205
211
  # on_empty { puts 'No argument given!' }
206
212
  # end
213
+ # @since 1.5.0
207
214
  def on_empty(obj=nil, &block)
208
215
  @on_empty ||= (obj || block)
209
216
  end
data/lib/slop/option.rb CHANGED
@@ -23,6 +23,7 @@ class Slop
23
23
 
24
24
  # @overload argument_value=(value)
25
25
  # Set this options argument value
26
+ # @param [Object] value The value you'd like applied to this option
26
27
  attr_writer :argument_value
27
28
 
28
29
  # @param [Slop] slop
@@ -159,4 +160,4 @@ class Slop
159
160
  end
160
161
  end
161
162
  end
162
- end
163
+ end
data/lib/slop/options.rb CHANGED
@@ -17,8 +17,8 @@ class Slop
17
17
  # @return [Option] the option assoiated with this flag
18
18
  def [](flag)
19
19
  item = flag.to_s
20
- if item =~ /\A\d+\z/
21
- slice item.to_i
20
+ if flag.is_a?(Integer)
21
+ slice flag
22
22
  else
23
23
  find do |option|
24
24
  option.short_flag == item || option.long_flag == item
@@ -34,4 +34,4 @@ class Slop
34
34
  (heads + tails).map(&:to_s).join("\n")
35
35
  end
36
36
  end
37
- end
37
+ end
data/test/slop_test.rb CHANGED
@@ -247,6 +247,8 @@ class SlopTest < TestCase
247
247
  assert_kind_of Slop::Option, slop.options[:foo]
248
248
  assert_equal "bar", slop[:foo]
249
249
  assert_equal "bar", slop['foo']
250
+ assert_kind_of Slop::Option, slop.options[0]
251
+ assert_nil slop.options['0']
250
252
  end
251
253
 
252
254
  test 'printing help' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.1
5
+ version: 1.5.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lee Jarvis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-17 00:00:00 +01:00
13
+ date: 2011-04-18 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16