slop 3.4.5 → 3.4.6

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: 68937e18cd6530ee2f31c7ef36a4cd7cb8259f05
4
- data.tar.gz: bcfe723b43f378c5205b44c2b10aa063692d4241
3
+ metadata.gz: ee8bab0b8e39c57a64b27be99083022699b0b133
4
+ data.tar.gz: 908937f49a1e197b07710292385731891ca3eee1
5
5
  SHA512:
6
- metadata.gz: fd370624b2039b5367c994d0c3f5cbcfad850a8f9da3972d579c7c04f53e67204d7ade792e287099a8fdd83b784e13ca4f69250a9f20d587fc876e13dcb95c5c
7
- data.tar.gz: 5329b9d7c8c5afe7806e99fdc90bd0dd0e5da49c0b2c278df1cb9519c2cf478662911a1b5abfbee502d2dfa0927dddd3504a0fc517633ca763084b49b12fee69
6
+ metadata.gz: a0b5d7a91bd89cf4fe1a272a3aa804e1330c1cf2fd1b6152f25cb7655ee8de759de9763780d7c93c265f9369deea969aec750ad1b123afd3143065b64888d3d7
7
+ data.tar.gz: fab9002de7d781eb65b746fe03c01d9b7ba7075082d17afe3c3f57ccecf33425129e80f9ec4c90d1e40add93dc2e75a16e8fb0fa6d84ad19480dbd6a10a38daf
data/CHANGES.md CHANGED
@@ -1,7 +1,9 @@
1
- HEAD
2
- ----
1
+ 3.4.5 (2013-05-14)
2
+ ------------------
3
3
 
4
4
  * Allow specifying long options starting with numbers (#110, Peter Zotov)
5
+ * Ensure short-options still consume trailing arguments, ie `-abc foo`
6
+ should assign `foo` to the option `c` if it expects an argument (#114).
5
7
 
6
8
  3.4.4 (2013-03-12)
7
9
  ------------------
data/README.md CHANGED
@@ -4,7 +4,7 @@ Slop
4
4
  Slop is a simple option parser with an easy to remember syntax and friendly API.
5
5
  API Documentation is available [here](http://injekt.github.com/rdoc/slop/).
6
6
 
7
- [![Build Status](https://secure.travis-ci.org/injekt/slop.png)](http://travis-ci.org/injekt/slop)
7
+ [![Build Status](https://travis-ci.org/injekt/slop.png?branch=master)](http://travis-ci.org/injekt/slop)
8
8
 
9
9
  Usage
10
10
  -----
@@ -44,7 +44,7 @@ All of these options can be sent to `Slop.new` or `Slop.parse` in Hash form.
44
44
  * `strict` - Enable strict mode. When processing unknown options, Slop will
45
45
  raise an `InvalidOptionError`. **default:** *false*.
46
46
  * `help` - Automatically add the `--help` option. **default:** *false*.
47
- * `banner` - Set this options banner text. **default:** *nil*.
47
+ * `banner` - Set the help banner text. **default:** *nil*.
48
48
  * `ignore_case` - When enabled, `-A` will look for the `-a` option if `-A`
49
49
  does not exist. **default:** *false*.
50
50
  * `autocreate` - Autocreate options on the fly. **default:** *false*.
@@ -101,7 +101,7 @@ Autocreate
101
101
 
102
102
  Slop has an 'autocreate' feature. This feature is intended to create
103
103
  options on the fly, without having to specify them yourself. In some case,
104
- uses this code could be all you need in your application:
104
+ using this code could be all you need in your application:
105
105
 
106
106
  ```ruby
107
107
  # ruby run.rb --foo bar --baz --name lee
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.5'
7
+ VERSION = '3.4.6'
8
8
 
9
9
  # The main Error class, all Exception classes inherit from this class.
10
10
  class Error < StandardError; end
@@ -567,13 +567,16 @@ class Slop
567
567
  execute_option(option, nil, index)
568
568
  flags = argument.split('')
569
569
  flags.each do |key|
570
- next unless opt = fetch_option(key)
571
- opt.count += 1
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)
570
+ if opt = fetch_option(key)
571
+ opt.count += 1
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
575
578
  else
576
- execute_option(opt, nil, index, key)
579
+ raise InvalidOptionError, "Unknown option -#{key}" if strict?
577
580
  end
578
581
  end
579
582
  end
@@ -627,31 +630,22 @@ class Slop
627
630
  config[:optional_argument] = true if @config[:optional_arguments]
628
631
 
629
632
  if objects.last.is_a?(Hash)
630
- config.merge!(objects.last)
631
- objects.pop
633
+ config.merge!(objects.pop)
632
634
  end
635
+
633
636
  short = extract_short_flag(objects, config)
634
637
  long = extract_long_flag(objects, config)
635
- desc = objects[0].respond_to?(:to_str) ? objects.shift : nil
638
+ desc = objects.shift if objects[0].respond_to?(:to_str)
636
639
 
637
640
  Option.new(self, short, long, desc, config, &block)
638
641
  end
639
642
 
640
- # Extract the short flag from an item.
641
- #
642
- # objects - The Array of objects passed from #build_option.
643
- # config - The Hash of configuration options built in #build_option.
644
643
  def extract_short_flag(objects, config)
645
- flag = clean(objects.first)
646
-
647
- if flag.size == 2 && flag.end_with?('=')
648
- config[:argument] ||= true
649
- flag.chop!
650
- end
651
-
652
- if flag.size == 1
644
+ flag = objects[0].to_s
645
+ if flag =~ /\A-?\w=?\z/
646
+ config[:argument] ||= flag.end_with?('=')
653
647
  objects.shift
654
- flag
648
+ flag.delete('-=')
655
649
  end
656
650
  end
657
651
 
data/slop.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '3.4.5'
3
+ s.version = '3.4.6'
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'
data/test/slop_test.rb CHANGED
@@ -228,6 +228,17 @@ class SlopTest < TestCase
228
228
  assert_raises(Slop::InvalidOptionError) { opts.parse %w'-fabc' }
229
229
  end
230
230
 
231
+ test "raising InvalidOptionError for multiple short options" do
232
+ opts = Slop.new :strict => true
233
+ opts.on :L
234
+ assert_raises(Slop::InvalidOptionError) { opts.parse %w'-Ly' }
235
+
236
+ # but not with no strict mode!
237
+ opts = Slop.new
238
+ opts.on :L
239
+ assert opts.parse %w'-Ly'
240
+ end
241
+
231
242
  test "multiple_switches is enabled by default" do
232
243
  opts = Slop.new { on :f; on :b }
233
244
  opts.parse %w[ -fb ]
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.5
4
+ version: 3.4.6
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-05-14 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -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.3
82
+ rubygems_version: 2.0.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Simple Lightweight Option Parsing