Hello community, here is the log from the commit of package rubygem-slop for openSUSE:Factory checked in at 2015-04-25 09:53:04 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-slop (Old) and /work/SRC/openSUSE:Factory/.rubygem-slop.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-slop" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-slop/rubygem-slop.changes 2015-02-11 16:45:48.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-slop.new/rubygem-slop.changes 2015-04-25 11:25:44.000000000 +0200 @@ -1,0 +2,19 @@ +Thu Apr 23 08:19:27 UTC 2015 - [email protected] + +- updated to version 4.1.0 + Features: + * Support for FloatOption #156 (Rick Hull) + * Support for `limit` config to ArrayOption. + * Support for `tail` config to add options to the bottom of + the help text. + * Add explicit setter (#[]=) to Result class. #162 + * Implement flag gettings for UnknownOption and MissingArgument + error classes. #165 (sigurdsvela) + + Minor enhancements: + * Reset parser every time `parse` is called. + + Bug fixes: + * Remove "--" from unprocessed arguments #157 (David RodrÃguez). + +------------------------------------------------------------------- Old: ---- slop-4.0.0.gem New: ---- slop-4.1.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-slop.spec ++++++ --- /var/tmp/diff_new_pack.A4RJ8Q/_old 2015-04-25 11:25:45.000000000 +0200 +++ /var/tmp/diff_new_pack.A4RJ8Q/_new 2015-04-25 11:25:45.000000000 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-slop -Version: 4.0.0 +Version: 4.1.0 Release: 0 %define mod_name slop %define mod_full_name %{mod_name}-%{version} @@ -48,7 +48,7 @@ %install %gem_install \ - --doc-files="LICENSE README.md" \ + --doc-files="CHANGELOG.md LICENSE README.md" \ -f %gem_packages ++++++ slop-4.0.0.gem -> slop-4.1.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.travis.yml new/.travis.yml --- old/.travis.yml 2014-12-27 18:58:23.000000000 +0100 +++ new/.travis.yml 2015-04-18 12:21:36.000000000 +0200 @@ -1,5 +1,8 @@ rvm: - 2.0.0 + - 2.1 + - 2.2 + - rbx-2 notifications: email: on_success: change diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 1970-01-01 01:00:00.000000000 +0100 +++ new/CHANGELOG.md 2015-04-18 12:21:36.000000000 +0200 @@ -0,0 +1,27 @@ +Changelog +========= + +v4.1.0 (2015-04-18) +------------------- + +Features: + * Support for FloatOption #156 (Rick Hull) + * Support for `limit` config to ArrayOption. + * Support for `tail` config to add options to the bottom of + the help text. + * Add explicit setter (#[]=) to Result class. #162 + * Implement flag gettings for UnknownOption and MissingArgument + error classes. #165 (sigurdsvela) + +Minor enhancements: + * Reset parser every time `parse` is called. + +Bug fixes: + * Remove "--" from unprocessed arguments #157 (David RodrÃguez). + +v4.0.0 (2014-12-27) +------------------- + +Features: + * Rebuilt from the ground up. See the v3 changelog for all existing + changes: https://github.com/leejarvis/slop/blob/v3/CHANGES.md diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2014-12-27 18:58:23.000000000 +0100 +++ new/README.md 2015-04-18 12:21:36.000000000 +0200 @@ -46,6 +46,7 @@ o.string #=> Slop::StringOption, expects an argument o.bool #=> Slop::BoolOption, no argument, aliased to BooleanOption o.integer #=> Slop::IntegerOption, expects an argument, aliased to IntOption +o.float #=> Slop::FloatOption, expects an argument o.array #=> Slop::ArrayOption, expects an argument o.null #=> Slop::NullOption, no argument and ignored from `to_hash` o.on #=> alias for o.null @@ -248,3 +249,85 @@ You can use version 3 of Slop (see `v3` branch). I also expect there to be some external libraries released soon that wrap around Slop to provide support for this feature. I'll update this document when that happens. + +Upgrading from version 3 +------------------------ + +Slop v4 is completely non-backwards compatible. The code has been rewritten +from the group up. If you're already using version 3 you have *have* to update +your code to use version 4. Here's an overview of the more fundamental changes: + +#### No more `instance_eval` + +Before: + +```ruby +Slop.parse do + on 'v', 'version' do + puts VERSION + end +end +``` + +After: + +```ruby +Slop.parse do |o| + o.on '-v', '--version' do + puts VERSION + end +end +``` + +#### No more `as` for option types + +Instead, the type is declared in the method call. Before: + +```ruby +on 'port=', as: Integer +``` + +After: + +```ruby +o.int '--port' # or integer +``` + +See the custom types section of the document. + +#### No more trailing `=` + +Instead, the "does this option expect an argument" question is answered by +the option type (i.e `on` and `bool` options do not expect arguments, all +others do. They handle type conversion, too. + +#### Hyphens are required + +This was a hard decision to make, but you must provide prefixed hyphens when +declaring your flags. This makes the underlying code much nicer and much less +ambiguous, which leads to less error prone code. It also means you can easily +support single hyphen prefix for a long flag, i.e `-hostname` which you +could not do before. It also provides a hidden feature, which is infinity flag +aliases: `o.string '-f', '-x', '--foo', '--bar', 'this is insane'` + +#### Strict is now on by default + +v3 had a `strict` option. v4 has no such option, and to suppress errors you can +instead provide the `suppress_errors: true` option to Slop. + +#### No more parse! + +Where v3 has both `Slop.parse` and `Slop.parse!`, v4 only has `parse`. The +former was used to decide whether Slop should or should not mutate the +original args (usually ARGV). This is almost never what you want, and it +can lead to confusion. Instead, `Slop::Result` provides an `arguments` +methods: + +```ruby +opts = Slop.parse do |o| + o.string '--hostname', '...' +end + +# ARGV is "hello --hostname foo bar" +p opts.arguments #=> ["hello", "bar"] +``` Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/error.rb new/lib/slop/error.rb --- old/lib/slop/error.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/error.rb 2015-04-18 12:21:36.000000000 +0200 @@ -12,9 +12,24 @@ # executed without one. Suppress with the `suppress_errors` # config option. class MissingArgument < Error + attr_reader :flags + + # Get all the flags that matches + # the option with the missing argument + def initialize(msg, flags) + super(msg) + @flags = flags + end end # Raised when an unknown option is parsed. Suppress # with the `suppress_errors` config option. - class UnknownOption < Error; end + class UnknownOption < Error + attr_reader :flag + + def initialize(msg, flag) + super(msg) + @flag = flag + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/option.rb new/lib/slop/option.rb --- old/lib/slop/option.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/option.rb 2015-04-18 12:21:36.000000000 +0200 @@ -1,7 +1,8 @@ module Slop class Option DEFAULT_CONFIG = { - help: true + help: true, + tail: false, } # An Array of flags this option matches. @@ -47,7 +48,7 @@ @count += 1 if value.nil? && expects_argument? && !suppress_errors? - raise Slop::MissingArgument, "missing argument for #{flag}" + raise Slop::MissingArgument.new("missing argument for #{flag}", flags) end @value = call(value) @@ -109,6 +110,17 @@ config[:help] end + # Returns true if this option should be added to the tail of the help text. + def tail? + config[:tail] + end + + # Returns 1 if this option should be added to the tail of the help text. + # Used for sorting. + def tail + tail? ? 1 : -1 + end + # Returns the help text for this option (flags and description). def to_s(offset: 0) "%-#{offset}s %s" % [flag, desc] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/options.rb new/lib/slop/options.rb --- old/lib/slop/options.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/options.rb 2015-04-18 12:21:36.000000000 +0200 @@ -101,7 +101,7 @@ str = config[:banner] ? "#{banner}\n" : "" len = longest_flag_length - options.select(&:help?).each_with_index do |opt, i| + options.select(&:help?).sort_by(&:tail).each_with_index do |opt, i| # use the index to fetch an associated separator if sep = separators[i] str << "#{sep}\n" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/parser.rb new/lib/slop/parser.rb --- old/lib/slop/parser.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/parser.rb 2015-04-18 12:21:36.000000000 +0200 @@ -34,6 +34,8 @@ # # Returns a Slop::Result. def parse(strings) + reset # reset before every parse + pairs = strings.each_cons(2).to_a # this ensures we still support the last string being a flag, # otherwise it'll only be used as an argument. @@ -42,8 +44,13 @@ @arguments = strings.dup pairs.each do |flag, arg| + break if !flag + # ignore everything after '--', flag or not - break if !flag || flag == '--' + if flag == '--' + arguments.delete(flag) + break + end # support `foo=bar` if flag.include?("=") @@ -95,7 +102,7 @@ try_process(last, arg) # send the argument to the last flag else if flag.start_with?("-") && !suppress_errors? - raise UnknownOption, "unknown option `#{flag}'" + raise UnknownOption.new("unknown option `#{flag}'", "#{flag}") end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/result.rb new/lib/slop/result.rb --- old/lib/slop/result.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/result.rb 2015-04-18 12:21:36.000000000 +0200 @@ -20,6 +20,17 @@ end alias get [] + # Set the value for an option. Raises an ArgumentError if the option + # does not exist. + def []=(flag, value) + if o = option(flag) + o.value = value + else + raise ArgumentError, "no option with flag `#{flag}'" + end + end + alias set []= + # Returns an Option if it exists. Ignores any prefixed hyphens. def option(flag) cleaned = -> (f) { f.to_s.sub(/\A--?/, '') } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop/types.rb new/lib/slop/types.rb --- old/lib/slop/types.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop/types.rb 2015-04-18 12:21:36.000000000 +0200 @@ -1,10 +1,14 @@ module Slop + # Cast the option argument to a String. class StringOption < Option def call(value) value.to_s end end + # Cast the option argument to true or false. + # Override default_value to default to false instead of nil. + # This option type does not expect an argument. class BoolOption < Option def call(_value) true @@ -20,6 +24,7 @@ end BooleanOption = BoolOption + # Cast the option argument to an Integer. class IntegerOption < Option def call(value) value =~ /\A\d+\z/ && value.to_i @@ -27,10 +32,20 @@ end IntOption = IntegerOption + # Cast the option argument to a Float. + class FloatOption < Option + def call(value) + # TODO: scientific notation, etc. + value =~ /\A\d*\.*\d+\z/ && value.to_f + end + end + + # Collect multiple items into a single Array. Support + # arguments separated by commas or multiple occurences. class ArrayOption < Option def call(value) @value ||= [] - @value.concat value.split(delimiter) + @value.concat value.split(delimiter, limit) end def default_value @@ -40,9 +55,14 @@ def delimiter config[:delimiter] || "," end + + def limit + config[:limit] || 0 + end end - # an option that discards the return value + # An option that discards the return value, inherits from Bool + # since it does not expect an argument. class NullOption < BoolOption def null? true diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/slop.rb new/lib/slop.rb --- old/lib/slop.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/lib/slop.rb 2015-04-18 12:21:36.000000000 +0200 @@ -6,8 +6,7 @@ require 'slop/error' module Slop - # The current version of Slop, of course. - VERSION = '4.0.0' + VERSION = '4.1.0' # Parse an array of options (defaults to ARGV). Accepts an # optional hash of configuration options and block. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2014-12-27 18:58:23.000000000 +0100 +++ new/metadata 2015-04-18 12:21:36.000000000 +0200 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: slop version: !ruby/object:Gem::Version - version: 4.0.0 + version: 4.1.0 platform: ruby authors: - Lee Jarvis autorequire: bindir: bin cert_chain: [] -date: 2014-12-27 00:00:00.000000000 Z +date: 2015-04-18 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rake @@ -46,6 +46,7 @@ files: - ".gitignore" - ".travis.yml" +- CHANGELOG.md - Gemfile - LICENSE - README.md @@ -85,7 +86,7 @@ version: '0' requirements: [] rubyforge_project: -rubygems_version: 2.2.2 +rubygems_version: 2.4.5 signing_key: specification_version: 4 summary: Simple Lightweight Option Parsing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/error_test.rb new/test/error_test.rb --- old/test/error_test.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/test/error_test.rb 2015-04-18 12:21:36.000000000 +0200 @@ -7,6 +7,13 @@ opts = Slop::Options.new opts.string "-n", "--name" assert_raises(Slop::MissingArgument) { opts.parse %w(--name) } + + #Assert returns the argument question + begin + opts.parse %w(--name) + rescue Slop::MissingArgument => e + assert_equal(e.flags, ["-n", "--name"]) + end end it "does not raise when errors are suppressed" do @@ -21,6 +28,13 @@ opts = Slop::Options.new opts.string "-n", "--name" assert_raises(Slop::UnknownOption) { opts.parse %w(--foo) } + + #Assert returns the unknown option in question + begin + opts.parse %w(--foo) + rescue Slop::UnknownOption => e + assert_equal(e.flag, "--foo") + end end it "does not raise when errors are suppressed" do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/options_test.rb new/test/options_test.rb --- old/test/options_test.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/test/options_test.rb 2015-04-18 12:21:36.000000000 +0200 @@ -75,5 +75,11 @@ @options.on "-x", "something", help: false refute_match(/something/, @options.to_s) end + + it "adds 'tail' options to the bottom of the help text" do + @options.on "-h", "--help", tail: true + @options.on "-f", "--foo" + assert_match(/^ -h, --help/, @options.to_s.lines.last) + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/parser_test.rb new/test/parser_test.rb --- old/test/parser_test.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/test/parser_test.rb 2015-04-18 12:21:36.000000000 +0200 @@ -11,13 +11,13 @@ end it "ignores everything after --" do - @parser.reset.parse %w(-v -- --name lee) + @parser.parse %w(-v -- --name lee) assert_equal [@verbose], @parser.used_options end it "parses flag=argument" do @options.integer "-p", "--port" - @result.parser.reset.parse %w(--name=bob -p=123) + @result.parser.parse %w(--name=bob -p=123) assert_equal "bob", @result[:name] assert_equal 123, @result[:port] end @@ -28,19 +28,19 @@ end it "parses boolean flags" do - @result.parser.reset.parse %w(-qv) + @result.parser.parse %w(-qv) assert_equal true, @result.quiet? assert_equal true, @result.verbose? end it "sends the argument to the last flag" do - @result.parser.reset.parse %w(-qvn foo) + @result.parser.parse %w(-qvn foo) assert_equal "foo", @result[:name] end it "doesn't screw up single hyphen long options" do @options.string "-host" - @result.parser.reset.parse %w(-host localhost) + @result.parser.parse %w(-host localhost) assert_equal "localhost", @result[:host] end end @@ -61,5 +61,10 @@ it "returns all unparsed arguments" do assert_equal %w(foo argument), @parser.arguments end + + it "does not return --" do + @parser.parse %w(-v -- --name lee) + assert_equal %w(--name lee), @parser.arguments + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/result_test.rb new/test/result_test.rb --- old/test/result_test.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/test/result_test.rb 2015-04-18 12:21:36.000000000 +0200 @@ -22,27 +22,27 @@ it "increments option count" do # test this here so it's more "full stack" assert_equal 1, @verbose.count - @result.parser.reset.parse %w(-v --verbose) + @result.parser.parse %w(-v --verbose) assert_equal 2, @verbose.count end it "handles default values" do @options.string("--foo", default: "bar") - @result.parser.reset.parse %w() + @result.parser.parse %w() assert_equal "bar", @result[:foo] end it "handles custom finishing" do @options.string "--foo" @options.reverse_everything "-r" - @result.parser.reset.parse %w(-r --name lee --foo bar) + @result.parser.parse %w(-r --name lee --foo bar) assert_equal %w(eel rab), @result.to_hash.values_at(:name, :foo) end it "yields arguments to option blocks" do output = nil @options.string("--foo") { |v| output = v } - @result.parser.reset.parse %w(--foo bar) + @result.parser.parse %w(--foo bar) assert_equal output, "bar" end @@ -54,6 +54,20 @@ end end + describe "#[]=" do + it "sets an options value" do + assert_equal "lee", @result["name"] + @result["name"] = "bob" + assert_equal "bob", @result[:name] + end + + it "raises if an option isn't found" do + assert_raises ArgumentError do + @result["zomg"] = "something" + end + end + end + describe "#method_missing" do it "checks if options have been used" do assert_equal true, @result.verbose? diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/types_test.rb new/test/types_test.rb --- old/test/types_test.rb 2014-12-27 18:58:23.000000000 +0100 +++ new/test/types_test.rb 2015-04-18 12:21:36.000000000 +0200 @@ -29,16 +29,35 @@ end it "returns nil for non-numbers by default" do - @result.parser.reset.parse %w(--age hello) + @result.parser.parse %w(--age hello) assert_equal nil, @result[:age] end end +describe Slop::FloatOption do + before do + @options = Slop::Options.new + @apr = @options.float "--apr" + @apr_value = 2.9 + @result = @options.parse %W(--apr #{@apr_value}) + end + + it "returns the value as a float" do + assert_equal @apr_value, @result[:apr] + end + + it "returns nil for non-numbers by default" do + @result.parser.parse %w(--apr hello) + assert_equal nil, @result[:apr] + end +end + describe Slop::ArrayOption do before do @options = Slop::Options.new @files = @options.array "--files" @delim = @options.array "-d", delimiter: ":" + @limit = @options.array "-l", limit: 2 @result = @options.parse %w(--files foo.txt,bar.rb) end @@ -51,14 +70,19 @@ end it "collects multiple option values" do - @result.parser.reset.parse %w(--files foo.txt --files bar.rb) + @result.parser.parse %w(--files foo.txt --files bar.rb) assert_equal %w(foo.txt bar.rb), @result[:files] end it "can use a custom delimiter" do - @result.parser.reset.parse %w(-d foo.txt:bar.rb) + @result.parser.parse %w(-d foo.txt:bar.rb) assert_equal %w(foo.txt bar.rb), @result[:d] end + + it "can use a custom limit" do + @result.parser.parse %w(-l foo,bar,baz) + assert_equal ["foo", "bar,baz"], @result[:l] + end end describe Slop::NullOption do
