[DRE-commits] [ruby-slop] 01/04: Imported Upstream version 3.4.6

Youhei SASAKI uwabami-guest at alioth.debian.org
Mon Aug 5 14:04:55 UTC 2013


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch master
in repository ruby-slop.

commit 3896a7a0ce2256b22a7e4784fa45c214008e9a04
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Mon Aug 5 22:53:05 2013 +0900

    Imported Upstream version 3.4.6
---
 CHANGES.md        |    6 ++++--
 README.md         |    6 +++---
 checksums.yaml.gz |  Bin 268 -> 268 bytes
 lib/slop.rb       |   40 +++++++++++++++++-----------------------
 metadata.yml      |    6 +++---
 slop.gemspec      |    2 +-
 test/slop_test.rb |   11 +++++++++++
 7 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 752d3d9..aa1e829 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,7 +1,9 @@
-HEAD
-----
+3.4.5 (2013-05-14)
+------------------
 
 * Allow specifying long options starting with numbers (#110, Peter Zotov)
+* Ensure short-options still consume trailing arguments, ie `-abc foo`
+  should assign `foo` to the option `c` if it expects an argument (#114).
 
 3.4.4 (2013-03-12)
 ------------------
diff --git a/README.md b/README.md
index dd8d5c5..4650376 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Slop
 Slop is a simple option parser with an easy to remember syntax and friendly API.
 API Documentation is available [here](http://injekt.github.com/rdoc/slop/).
 
-[![Build Status](https://secure.travis-ci.org/injekt/slop.png)](http://travis-ci.org/injekt/slop)
+[![Build Status](https://travis-ci.org/injekt/slop.png?branch=master)](http://travis-ci.org/injekt/slop)
 
 Usage
 -----
@@ -44,7 +44,7 @@ All of these options can be sent to `Slop.new` or `Slop.parse` in Hash form.
 * `strict` - Enable strict mode. When processing unknown options, Slop will
   raise an `InvalidOptionError`. **default:** *false*.
 * `help` - Automatically add the `--help` option. **default:** *false*.
-* `banner` - Set this options banner text. **default:** *nil*.
+* `banner` - Set the help banner text. **default:** *nil*.
 * `ignore_case` - When enabled, `-A` will look for the `-a` option if `-A`
   does not exist. **default:** *false*.
 * `autocreate` - Autocreate options on the fly. **default:** *false*.
@@ -101,7 +101,7 @@ Autocreate
 
 Slop has an 'autocreate' feature. This feature is intended to create
 options on the fly, without having to specify them yourself. In some case,
-uses this code could be all you need in your application:
+using this code could be all you need in your application:
 
 ```ruby
 # ruby run.rb --foo bar --baz --name lee
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
index 8600526..243b409 100644
Binary files a/checksums.yaml.gz and b/checksums.yaml.gz differ
diff --git a/lib/slop.rb b/lib/slop.rb
index f217cdc..3a5c9d0 100644
--- a/lib/slop.rb
+++ b/lib/slop.rb
@@ -4,7 +4,7 @@ require 'slop/commands'
 class Slop
   include Enumerable
 
-  VERSION = '3.4.5'
+  VERSION = '3.4.6'
 
   # The main Error class, all Exception classes inherit from this class.
   class Error < StandardError; end
@@ -567,13 +567,16 @@ class Slop
     execute_option(option, nil, index)
     flags = argument.split('')
     flags.each do |key|
-      next unless opt = fetch_option(key)
-      opt.count += 1
-      if (opt.expects_argument? || opt.accepts_optional_argument?) &&
-          (flags[-1] == opt.key) && (val = items[index+1])
-        execute_option(opt, val, index, key)
+      if opt = fetch_option(key)
+        opt.count += 1
+        if (opt.expects_argument? || opt.accepts_optional_argument?) &&
+            (flags[-1] == opt.key) && (val = items[index+1])
+          execute_option(opt, val, index, key)
+        else
+          execute_option(opt, nil, index, key)
+        end
       else
-        execute_option(opt, nil, index, key)
+        raise InvalidOptionError, "Unknown option -#{key}" if strict?
       end
     end
   end
@@ -627,31 +630,22 @@ class Slop
     config[:optional_argument] = true if @config[:optional_arguments]
 
     if objects.last.is_a?(Hash)
-      config.merge!(objects.last)
-      objects.pop
+      config.merge!(objects.pop)
     end
+
     short = extract_short_flag(objects, config)
     long  = extract_long_flag(objects, config)
-    desc  = objects[0].respond_to?(:to_str) ? objects.shift : nil
+    desc  = objects.shift if objects[0].respond_to?(:to_str)
 
     Option.new(self, short, long, desc, config, &block)
   end
 
-  # Extract the short flag from an item.
-  #
-  # objects - The Array of objects passed from #build_option.
-  # config  - The Hash of configuration options built in #build_option.
   def extract_short_flag(objects, config)
-    flag = clean(objects.first)
-
-    if flag.size == 2 && flag.end_with?('=')
-      config[:argument] ||= true
-      flag.chop!
-    end
-
-    if flag.size == 1
+    flag = objects[0].to_s
+    if flag =~ /\A-?\w=?\z/
+      config[:argument] ||= flag.end_with?('=')
       objects.shift
-      flag
+      flag.delete('-=')
     end
   end
 
diff --git a/metadata.yml b/metadata.yml
index 79ad786..307e8f5 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,14 +1,14 @@
 --- !ruby/object:Gem::Specification
 name: slop
 version: !ruby/object:Gem::Version
-  version: 3.4.5
+  version: 3.4.6
 platform: ruby
 authors:
 - Lee Jarvis
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2013-05-14 00:00:00.000000000 Z
+date: 2013-07-25 00:00:00.000000000 Z
 dependencies:
 - !ruby/object:Gem::Dependency
   name: rake
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
       version: '0'
 requirements: []
 rubyforge_project: 
-rubygems_version: 2.0.3
+rubygems_version: 2.0.2
 signing_key: 
 specification_version: 4
 summary: Simple Lightweight Option Parsing
diff --git a/slop.gemspec b/slop.gemspec
index c688729..9bb971e 100644
--- a/slop.gemspec
+++ b/slop.gemspec
@@ -1,6 +1,6 @@
 Gem::Specification.new do |s|
   s.name        = 'slop'
-  s.version     = '3.4.5'
+  s.version     = '3.4.6'
   s.summary     = 'Simple Lightweight Option Parsing'
   s.description = 'A simple DSL for gathering options and parsing the command line'
   s.author      = 'Lee Jarvis'
diff --git a/test/slop_test.rb b/test/slop_test.rb
index 856a58b..1fd0955 100644
--- a/test/slop_test.rb
+++ b/test/slop_test.rb
@@ -228,6 +228,17 @@ class SlopTest < TestCase
     assert_raises(Slop::InvalidOptionError) { opts.parse %w'-fabc' }
   end
 
+  test "raising InvalidOptionError for multiple short options" do
+    opts = Slop.new :strict => true
+    opts.on :L
+    assert_raises(Slop::InvalidOptionError) { opts.parse %w'-Ly' }
+
+    # but not with no strict mode!
+    opts = Slop.new
+    opts.on :L
+    assert opts.parse %w'-Ly'
+  end
+
   test "multiple_switches is enabled by default" do
     opts = Slop.new { on :f; on :b }
     opts.parse %w[ -fb ]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-slop.git



More information about the Pkg-ruby-extras-commits mailing list