Hello community, here is the log from the commit of package rubygem-cri for openSUSE:Factory checked in at 2017-04-17 10:27:05 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-cri (Old) and /work/SRC/openSUSE:Factory/.rubygem-cri.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-cri" Mon Apr 17 10:27:05 2017 rev:4 rq:487593 version:2.8.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-cri/rubygem-cri.changes 2016-12-16 11:54:58.258355691 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-cri.new/rubygem-cri.changes 2017-04-17 10:27:08.859107349 +0200 @@ -1,0 +2,14 @@ +Sun Apr 2 04:31:14 UTC 2017 - [email protected] + +- updated to version 2.8.0 + see installed NEWS.md + + 2.8.0 + ----- + + Features: + + * Allow passing `hard_exit: false` to `Command#run` to prevent `SystemExit` (#51) + * Allow specifying the default subcommand (#54) + +------------------------------------------------------------------- Old: ---- cri-2.7.1.gem New: ---- cri-2.8.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-cri.spec ++++++ --- /var/tmp/diff_new_pack.OdLKVp/_old 2017-04-17 10:27:09.479019559 +0200 +++ /var/tmp/diff_new_pack.OdLKVp/_new 2017-04-17 10:27:09.483018992 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-cri # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,7 +24,7 @@ # Name: rubygem-cri -Version: 2.7.1 +Version: 2.8.0 Release: 0 %define mod_name cri %define mod_full_name %{mod_name}-%{version} ++++++ cri-2.7.1.gem -> cri-2.8.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile.lock new/Gemfile.lock --- old/Gemfile.lock 2016-12-03 18:24:58.000000000 +0100 +++ new/Gemfile.lock 2017-04-01 13:56:35.000000000 +0200 @@ -7,54 +7,41 @@ GEM remote: https://rubygems.org/ specs: - asciidoctor (1.5.2) + asciidoctor (1.5.5) ast (2.3.0) colored (1.2) - coveralls (0.8.1) - json (~> 1.8) - rest-client (>= 1.6.8, < 2) - simplecov (~> 0.10.0) + coveralls (0.8.20) + json (>= 1.8, < 3) + simplecov (~> 0.14.1) term-ansicolor (~> 1.3) - thor (~> 0.19.1) + thor (~> 0.19.4) + tins (~> 1.6) docile (1.1.5) - domain_name (0.5.24) - unf (>= 0.0.5, < 1.0.0) - http-cookie (1.0.2) - domain_name (~> 0.5) - json (1.8.2) - mime-types (2.5) - minitest (5.6.1) - netrc (0.10.3) - parser (2.3.3.1) + json (2.0.3) + minitest (5.10.1) + parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) - rainbow (2.1.0) - rake (10.4.2) - rest-client (1.8.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 3.0) - netrc (~> 0.7) - rubocop (0.46.0) - parser (>= 2.3.1.1, < 3.0) + rainbow (2.2.1) + rake (12.0.0) + rubocop (0.48.0) + parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) - simplecov (0.10.0) + simplecov (0.14.1) docile (~> 1.1.0) - json (~> 1.8) + json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - term-ansicolor (1.3.0) + term-ansicolor (1.5.0) tins (~> 1.0) - thor (0.19.1) - tins (1.5.1) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.1) - unicode-display_width (1.1.1) - yard (0.8.7.6) + thor (0.19.4) + tins (1.13.2) + unicode-display_width (1.1.3) + yard (0.9.8) PLATFORMS ruby @@ -70,4 +57,4 @@ yard BUNDLED WITH - 1.13.6 + 1.14.6 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/NEWS.md new/NEWS.md --- old/NEWS.md 2016-12-03 18:24:58.000000000 +0100 +++ new/NEWS.md 2017-04-01 13:56:35.000000000 +0200 @@ -1,6 +1,14 @@ Cri News ======== +2.8.0 +----- + +Features: + +* Allow passing `hard_exit: false` to `Command#run` to prevent `SystemExit` (#51) +* Allow specifying the default subcommand (#54) + 2.7.1 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.adoc new/README.adoc --- old/README.adoc 2016-12-03 18:24:58.000000000 +0100 +++ new/README.adoc 2017-04-01 13:56:35.000000000 +0200 @@ -9,6 +9,10 @@ Cri is a library for building easy-to-use command-line tools with support for nested commands. +== Requirements == + +Cri requires Ruby 2.1 or newer. + == Usage == The central concept in Cri is the _command_, which has option definitions as @@ -189,6 +193,14 @@ root.cmd.add_command(cmd_init) -------------------------------------------------------------------------------- +You can specify a default subcommand. This subcommand will be executed when the +command has subcommands, and no subcommands are otherwise explicitly specified: + +[source,ruby] +-------------------------------------------------------------------------------- +default_subcommand 'compile' +-------------------------------------------------------------------------------- + == Contributors == * Toon Willems diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Rakefile new/Rakefile --- old/Rakefile 2016-12-03 18:24:58.000000000 +0100 +++ new/Rakefile 2017-04-01 13:56:35.000000000 +0200 @@ -14,18 +14,15 @@ ] end -task :test_unit do - require './test/helper.rb' - - FileList['./test/**/test_*.rb', './test/**/*_spec.rb'].each do |fn| - require fn - end +Rake::TestTask.new(:test_unit) do |t| + t.test_files = Dir['test/**/*_spec.rb'] + Dir['test/**/test_*.rb'] + t.libs << 'test' end RuboCop::RakeTask.new(:test_style) do |task| task.options = %w(--display-cop-names --format simple) end -task test: [:test_unit, :test_style] +task test: %i(test_unit test_style) task default: :test Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/cri/command.rb new/lib/cri/command.rb --- old/lib/cri/command.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/lib/cri/command.rb 2017-04-01 13:56:35.000000000 +0200 @@ -38,6 +38,20 @@ end end + # Signals that Cri should abort execution. Unless otherwise specified using the `hard_exit` + # param, this exception will cause Cri to exit the running process. + # + # @api private + class CriExitException < StandardError + def initialize(is_error:) + @is_error = is_error + end + + def error? + @is_error + end + end + # @return [Cri::Command, nil] This command’s supercommand, or nil if the # command has no supercommand attr_accessor :supercommand @@ -46,6 +60,9 @@ attr_accessor :commands alias subcommands commands + # @return [Symbol] The name of the default subcommand + attr_accessor :default_subcommand_name + # @return [String] The name attr_accessor :name @@ -123,6 +140,7 @@ @aliases = Set.new @commands = Set.new @option_definitions = Set.new + @default_subcommand_name = nil end # Modifies the command using the DSL. @@ -211,19 +229,21 @@ # @param [String] name The full, partial or aliases name of the command # # @return [Cri::Command] The command with the given name - def command_named(name) + def command_named(name, hard_exit: true) commands = commands_named(name) if commands.empty? $stderr.puts "#{self.name}: unknown command '#{name}'\n" - exit 1 + raise CriExitException.new(is_error: true) elsif commands.size > 1 $stderr.puts "#{self.name}: '#{name}' is ambiguous:" $stderr.puts " #{commands.map(&:name).sort.join(' ')}" - exit 1 + raise CriExitException.new(is_error: true) else commands[0] end + rescue CriExitException => e + exit(e.error? ? 1 : 0) if hard_exit end # Runs the command with the given command-line arguments, possibly invoking @@ -235,7 +255,7 @@ # supercommand # # @return [void] - def run(opts_and_args, parent_opts = {}) + def run(opts_and_args, parent_opts = {}, hard_exit: true) # Parse up to command name stuff = partition(opts_and_args) opts_before_subcmd, subcmd_name, opts_and_args_after_subcmd = *stuff @@ -248,14 +268,21 @@ # Get command if subcmd_name.nil? - $stderr.puts "#{name}: no command given" - exit 1 + if default_subcommand_name + subcmd_name = default_subcommand_name + else + $stderr.puts "#{name}: no command given" + raise CriExitException.new(is_error: true) + end end - subcommand = command_named(subcmd_name) + subcommand = command_named(subcmd_name, hard_exit: hard_exit) + return if subcommand.nil? # Run - subcommand.run(opts_and_args_after_subcmd, opts_before_subcmd) + subcommand.run(opts_and_args_after_subcmd, opts_before_subcmd, hard_exit: hard_exit) end + rescue CriExitException => e + exit(e.error? ? 1 : 0) if hard_exit end # Runs the actual command with the given command-line arguments, not @@ -343,10 +370,10 @@ yield rescue Cri::OptionParser::IllegalOptionError => e $stderr.puts "#{name}: illegal option -- #{e}" - exit 1 + raise CriExitException.new(is_error: true) rescue Cri::OptionParser::OptionRequiresAnArgumentError => e $stderr.puts "#{name}: option requires an argument -- #{e}" - exit 1 + raise CriExitException.new(is_error: true) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/cri/command_dsl.rb new/lib/cri/command_dsl.rb --- old/lib/cri/command_dsl.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/lib/cri/command_dsl.rb 2017-04-01 13:56:35.000000000 +0200 @@ -31,6 +31,17 @@ @command.add_command(command) end + # Sets the name of the default subcommand, i.e. the subcommand that will + # be executed if no subcommand is explicitly specified. This is `nil` by + # default, and will typically only be set for the root command. + # + # @param [String, nil] name The name of the default subcommand + # + # @return [void] + def default_subcommand(name) + @command.default_subcommand_name = name + end + # Sets the command name. # # @param [String] arg The new command name diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/cri/commands/basic_root.rb new/lib/cri/commands/basic_root.rb --- old/lib/cri/commands/basic_root.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/lib/cri/commands/basic_root.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,6 +1,6 @@ flag :h, :help, 'show help for this command' do |_value, cmd| puts cmd.help - exit 0 + raise CriExitException.new(is_error: false) end subcommand Cri::Command.new_basic_help diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/cri/option_parser.rb new/lib/cri/option_parser.rb --- old/lib/cri/option_parser.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/lib/cri/option_parser.rb 2017-04-01 13:56:35.000000000 +0200 @@ -199,7 +199,7 @@ definition = @definitions.find { |d| d[:long] == option_key } raise IllegalOptionError.new(option_key) if definition.nil? - if [:required, :optional].include?(definition[:argument]) + if %i(required optional).include?(definition[:argument]) # Get option value if necessary if option_value.nil? option_value = find_option_value(definition, option_key) @@ -226,7 +226,7 @@ if option_keys.length > 1 && definition[:argument] == :required # This is a combined option and it requires an argument, so complain raise OptionRequiresAnArgumentError.new(option_key) - elsif [:required, :optional].include?(definition[:argument]) + elsif %i(required optional).include?(definition[:argument]) # Get option value option_value = find_option_value(definition, option_key) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/cri/version.rb new/lib/cri/version.rb --- old/lib/cri/version.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/lib/cri/version.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,4 +1,4 @@ module Cri # The current Cri version. - VERSION = '2.7.1'.freeze + VERSION = '2.8.0'.freeze end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2016-12-03 18:24:58.000000000 +0100 +++ new/metadata 2017-04-01 13:56:35.000000000 +0200 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: cri version: !ruby/object:Gem::Version - version: 2.7.1 + version: 2.8.0 platform: ruby authors: - Denis Defreyne autorequire: bindir: bin cert_chain: [] -date: 2016-12-03 00:00:00.000000000 Z +date: 2017-04-01 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: colored @@ -101,7 +101,7 @@ version: '0' requirements: [] rubyforge_project: -rubygems_version: 2.6.8 +rubygems_version: 2.6.11 signing_key: specification_version: 4 summary: a library for building easy-to-use command-line tools diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_argument_array.rb new/test/test_argument_array.rb --- old/test/test_argument_array.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_argument_array.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class ArgumentArrayTestCase < Cri::TestCase def test_initialize diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_base.rb new/test/test_base.rb --- old/test/test_base.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_base.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class BaseTestCase < Cri::TestCase def test_stub; end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_basic_help.rb new/test/test_basic_help.rb --- old/test/test_basic_help.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_basic_help.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class BasicHelpTestCase < Cri::TestCase def test_run_without_supercommand diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_basic_root.rb new/test/test_basic_root.rb --- old/test/test_basic_root.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_basic_root.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,12 +1,25 @@ +require 'helper' + module Cri class BasicRootTestCase < Cri::TestCase def test_run_with_help cmd = Cri::Command.new_basic_root stdout, _stderr = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do cmd.run(%w(-h)) end + assert_equal 0, err.status + end + + assert stdout =~ /COMMANDS.*\n.*help.*show help/ + end + + def test_run_with_help_no_exit + cmd = Cri::Command.new_basic_root + + stdout, _stderr = capture_io_while do + cmd.run(%w(-h), {}, hard_exit: false) end assert stdout =~ /COMMANDS.*\n.*help.*show help/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_command.rb new/test/test_command.rb --- old/test/test_command.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_command.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class CommandTestCase < Cri::TestCase def simple_cmd @@ -145,9 +147,19 @@ def test_invoke_simple_with_missing_opt_arg out, err = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do simple_cmd.run(%w(-b)) end + assert_equal 1, err.status + end + + assert_equal [], lines(out) + assert_equal ['moo: option requires an argument -- b'], lines(err) + end + + def test_invoke_simple_with_missing_opt_arg_no_exit + out, err = capture_io_while do + simple_cmd.run(%w(-b), {}, hard_exit: false) end assert_equal [], lines(out) @@ -156,9 +168,19 @@ def test_invoke_simple_with_illegal_opt out, err = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do simple_cmd.run(%w(-z)) end + assert_equal 1, err.status + end + + assert_equal [], lines(out) + assert_equal ['moo: illegal option -- z'], lines(err) + end + + def test_invoke_simple_with_illegal_opt_no_exit + out, err = capture_io_while do + simple_cmd.run(%w(-z), {}, hard_exit: false) end assert_equal [], lines(out) @@ -176,9 +198,19 @@ def test_invoke_nested_without_opts_or_args out, err = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do nested_cmd.run(%w()) end + assert_equal 1, err.status + end + + assert_equal [], lines(out) + assert_equal ['super: no command given'], lines(err) + end + + def test_invoke_nested_without_opts_or_args_no_exit + out, err = capture_io_while do + nested_cmd.run(%w(), {}, hard_exit: false) end assert_equal [], lines(out) @@ -196,9 +228,19 @@ def test_invoke_nested_with_incorrect_command_name out, err = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do nested_cmd.run(%w(oogabooga)) end + assert_equal 1, err.status + end + + assert_equal [], lines(out) + assert_equal ["super: unknown command 'oogabooga'"], lines(err) + end + + def test_invoke_nested_with_incorrect_command_name_no_exit + out, err = capture_io_while do + nested_cmd.run(%w(oogabooga), {}, hard_exit: false) end assert_equal [], lines(out) @@ -207,9 +249,19 @@ def test_invoke_nested_with_ambiguous_command_name out, err = capture_io_while do - assert_raises SystemExit do + err = assert_raises SystemExit do nested_cmd.run(%w(s)) end + assert_equal 1, err.status + end + + assert_equal [], lines(out) + assert_equal ["super: 's' is ambiguous:", ' sink sub'], lines(err) + end + + def test_invoke_nested_with_ambiguous_command_name_no_exit + out, err = capture_io_while do + nested_cmd.run(%w(s), {}, hard_exit: false) end assert_equal [], lines(out) @@ -559,5 +611,26 @@ assert_equal [bar, foo, qux], [foo, bar, qux].sort end + + def test_default_subcommand + subcommand = Cri::Command.define do + name 'sub' + + run do |_opts, _args, _c| + $stdout.puts 'I am the subcommand!' + end + end + + cmd = Cri::Command.define do + name 'super' + default_subcommand 'sub' + subcommand subcommand + end + + out, _err = capture_io_while do + cmd.run([]) + end + assert_equal "I am the subcommand!\n", out + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_command_dsl.rb new/test/test_command_dsl.rb --- old/test/test_command_dsl.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_command_dsl.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class CommandDSLTestCase < Cri::TestCase def test_create_command diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_command_runner.rb new/test/test_command_runner.rb --- old/test/test_command_runner.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_command_runner.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class CommandRunnerTestCase < Cri::TestCase def setup diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_option_parser.rb new/test/test_option_parser.rb --- old/test/test_option_parser.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_option_parser.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class OptionParserTestCase < Cri::TestCase def test_parse_without_options diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_string_formatter.rb new/test/test_string_formatter.rb --- old/test/test_string_formatter.rb 2016-12-03 18:24:58.000000000 +0100 +++ new/test/test_string_formatter.rb 2017-04-01 13:56:35.000000000 +0200 @@ -1,3 +1,5 @@ +require 'helper' + module Cri class CoreExtTestCase < Cri::TestCase def formatter
