slop 3.4.4 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07ec5394f499e02a0abeb5341ed660ef3822dfa3
4
- data.tar.gz: 4cc1f6f9d754ae2b45c813c96c544669756650bd
3
+ metadata.gz: 68937e18cd6530ee2f31c7ef36a4cd7cb8259f05
4
+ data.tar.gz: bcfe723b43f378c5205b44c2b10aa063692d4241
5
5
  SHA512:
6
- metadata.gz: 2e11fa1d72ee94114ca1153ba79b0b114bf6720a60cb90d923f976e934c9988b8ea7bab24960b86115c65e31a5dbe6a715564f57efd97b13dd690210370d52ed
7
- data.tar.gz: f9ee6be396f7ae956ece36166d2c272b464dad70c1525d1a61eb0955181bee64973307694679ba634ec1baf97529b0509ed00d95cb1bdc1a29204d6867174f13
6
+ metadata.gz: fd370624b2039b5367c994d0c3f5cbcfad850a8f9da3972d579c7c04f53e67204d7ade792e287099a8fdd83b784e13ca4f69250a9f20d587fc876e13dcb95c5c
7
+ data.tar.gz: 5329b9d7c8c5afe7806e99fdc90bd0dd0e5da49c0b2c278df1cb9519c2cf478662911a1b5abfbee502d2dfa0927dddd3504a0fc517633ca763084b49b12fee69
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ HEAD
2
+ ----
3
+
4
+ * Allow specifying long options starting with numbers (#110, Peter Zotov)
5
+
1
6
  3.4.4 (2013-03-12)
2
7
  ------------------
3
8
 
data/README.md CHANGED
@@ -175,8 +175,8 @@ require 'slop'
175
175
 
176
176
  opts = Slop.parse do
177
177
  on :n, :name=, 'Your name'
178
- on :a, :age=, 'Your age', :as => :int
178
+ on :a, :age=, 'Your age', as: Integer
179
179
  end
180
180
 
181
181
  opts.to_hash #=> { :name => 'lee', :age => 105 }
182
- ```
182
+ ```
data/lib/slop.rb CHANGED
@@ -4,7 +4,7 @@ require 'slop/commands'
4
4
  class Slop
5
5
  include Enumerable
6
6
 
7
- VERSION = '3.4.4'
7
+ VERSION = '3.4.5'
8
8
 
9
9
  # The main Error class, all Exception classes inherit from this class.
10
10
  class Error < StandardError; end
@@ -61,7 +61,7 @@ class Slop
61
61
  # Returns a new instance of Slop.
62
62
  def parse!(items = ARGV, config = {}, &block)
63
63
  config, items = items, ARGV if items.is_a?(Hash) && config.empty?
64
- slop = Slop.new config, &block
64
+ slop = new config, &block
65
65
  slop.parse! items
66
66
  slop
67
67
  end
@@ -511,7 +511,7 @@ class Slop
511
511
  option.call(nil)
512
512
  end
513
513
  elsif config[:multiple_switches] && argument
514
- execute_multiple_switches(option, argument, index)
514
+ execute_multiple_switches(option, argument, items, index)
515
515
  else
516
516
  option.value = option.count > 0
517
517
  option.call(nil)
@@ -559,15 +559,22 @@ class Slop
559
559
  #
560
560
  # option - The first Option object.
561
561
  # argument - The argument to this option. (Split into multiple Options).
562
+ # items - The Array of items currently being parsed.
562
563
  # index - The index of the current item being processed.
563
564
  #
564
565
  # Returns nothing.
565
- def execute_multiple_switches(option, argument, index)
566
+ def execute_multiple_switches(option, argument, items, index)
566
567
  execute_option(option, nil, index)
567
- argument.split('').each do |key|
568
+ flags = argument.split('')
569
+ flags.each do |key|
568
570
  next unless opt = fetch_option(key)
569
571
  opt.count += 1
570
- execute_option(opt, nil, index, key)
572
+ if (opt.expects_argument? || opt.accepts_optional_argument?) &&
573
+ (flags[-1] == opt.key) && (val = items[index+1])
574
+ execute_option(opt, val, index, key)
575
+ else
576
+ execute_option(opt, nil, index, key)
577
+ end
571
578
  end
572
579
  end
573
580
 
@@ -654,7 +661,7 @@ class Slop
654
661
  # config - The Hash of configuration options built in #build_option.
655
662
  def extract_long_flag(objects, config)
656
663
  flag = objects.first.to_s
657
- if flag =~ /\A(?:--?)?[a-zA-Z][a-zA-Z0-9_-]+\=?\??\z/
664
+ if flag =~ /\A(?:--?)?[a-zA-Z0-9][a-zA-Z0-9_.-]+\=?\??\z/
658
665
  config[:argument] ||= true if flag.end_with?('=')
659
666
  config[:optional_argument] = true if flag.end_with?('=?')
660
667
  objects.shift
data/slop.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '3.4.4'
3
+ s.version = '3.4.5'
4
4
  s.summary = 'Simple Lightweight Option Parsing'
5
5
  s.description = 'A simple DSL for gathering options and parsing the command line'
6
6
  s.author = 'Lee Jarvis'
7
- s.email = 'lee@jarvis.co'
7
+ s.email = 'ljjarvis@gmail.com'
8
8
  s.homepage = 'http://github.com/injekt/slop'
9
9
  s.files = `git ls-files`.split("\n")
10
10
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -13,5 +13,5 @@ Gem::Specification.new do |s|
13
13
  s.required_ruby_version = '>= 1.8.7'
14
14
 
15
15
  s.add_development_dependency 'rake'
16
- s.add_development_dependency 'minitest'
16
+ s.add_development_dependency 'minitest', '~> 5.0.0'
17
17
  end
data/test/helper.rb CHANGED
@@ -1,14 +1,11 @@
1
1
  $VERBOSE = true
2
2
 
3
- unless Object.const_defined? 'Slop'
4
- $:.unshift File.expand_path('../../lib', __FILE__)
5
- require 'slop'
6
- end
3
+ require 'slop'
7
4
 
8
5
  require 'minitest/autorun'
9
6
  require 'stringio'
10
7
 
11
- class TestCase < MiniTest::Unit::TestCase
8
+ class TestCase < Minitest::Test
12
9
  def self.test(name, &block)
13
10
  define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
14
11
  end
data/test/slop_test.rb CHANGED
@@ -36,6 +36,7 @@ class SlopTest < TestCase
36
36
  assert_equal [nil, 'foo', nil, {}], build_option(:foo)
37
37
  assert_equal ['f', nil, 'Some description', {}], build_option(:f, 'Some description')
38
38
  assert_equal ['f', 'foo', nil, {}], build_option(:f, :foo)
39
+ assert_equal [nil, '1.8', 'Use v. 1.8', {}], build_option('--1.8', 'Use v. 1.8')
39
40
 
40
41
  # with arguments
41
42
  assert_equal ['f', nil, nil, {:argument=>true}], build_option('f=')
@@ -131,9 +132,11 @@ class SlopTest < TestCase
131
132
  end
132
133
 
133
134
  test "default help exits" do
134
- slop = Slop.new :help => true
135
- assert_raises SystemExit do
136
- slop.parse %w/--help/
135
+ temp_stdout do
136
+ slop = Slop.new :help => true
137
+ assert_raises SystemExit do
138
+ slop.parse %w/--help/
139
+ end
137
140
  end
138
141
  end
139
142
 
@@ -244,6 +247,12 @@ class SlopTest < TestCase
244
247
  assert_equal %w'foo', args
245
248
  end
246
249
 
250
+ test "multiple options should still accept trailing arguments" do
251
+ opts = Slop.new { on :a; on :b= }
252
+ opts.parse %w'-ab foo'
253
+ assert_equal 'foo', opts[:b]
254
+ end
255
+
247
256
  test "setting/getting the banner" do
248
257
  opts = Slop.new :banner => 'foo'
249
258
  assert_equal 'foo', opts.banner
@@ -339,13 +348,17 @@ class SlopTest < TestCase
339
348
  test "printing help with :help => true" do
340
349
  temp_stdout do |string|
341
350
  opts = Slop.new(:help => true, :banner => false)
342
- opts.parse %w( --help )
351
+ assert_raises SystemExit do
352
+ opts.parse %w( --help )
353
+ end
343
354
  assert_equal " -h, --help Display this help message.\n", string
344
355
  end
345
356
 
346
357
  temp_stdout do |string|
347
358
  opts = Slop.new(:help => true)
348
- opts.parse %w( --help )
359
+ assert_raises SystemExit do
360
+ opts.parse %w( --help )
361
+ end
349
362
  assert_equal "Usage: rake_test_loader [options]\n -h, --help Display this help message.\n", string
350
363
  end
351
364
  end
@@ -463,8 +476,10 @@ class SlopTest < TestCase
463
476
  assert_equal %w'--help foo bar', items
464
477
  items.clear
465
478
  temp_stdout do
466
- Slop.parse(%w'--help foo bar', :help => true) do
467
- run { |o, a| items.concat a }
479
+ assert_raises SystemExit do
480
+ Slop.parse(%w'--help foo bar', :help => true) do
481
+ run { |o, a| items.concat a }
482
+ end
468
483
  end
469
484
  assert_empty items
470
485
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.4
4
+ version: 3.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-12 00:00:00.000000000 Z
11
+ date: 2013-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,18 +28,18 @@ dependencies:
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 5.0.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 5.0.0
41
41
  description: A simple DSL for gathering options and parsing the command line
42
- email: lee@jarvis.co
42
+ email: ljjarvis@gmail.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.0.0
82
+ rubygems_version: 2.0.3
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Simple Lightweight Option Parsing