diff --git a/.rubocop.yml b/.rubocop.yml index 315d211..f4e3ef3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,3 +14,7 @@ RSpec/EmptyLineAfterHook: Naming/FileName: Exclude: - lib/ci-helper.rb + +Style/HashConversion: + Exclude: + - spec/**/*_spec.rb diff --git a/README.md b/README.md index 6b65ac5..61e464d 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,10 @@ A command can accept list of options (parameters). Option values are passed thro For example, the BundlerAudit command accepts the ignored_advisories option You can set a value of this option by setting the flag `--ignored-advisories ignored-advisory`. It should be noted that all hyphens in flag names are automatically replaced with underscores. +If command accepts array as option's value, you can separate values with either commas or spaces. ```bash -$ ci-helper BundlerAudit --ignored-advisories first,second +$ ci-helper BundlerAudit --ignored-advisories first,second # Valid +$ ci-helper BundlerAudit --ignored-advisories first second # Valid too! ``` List of available commands: diff --git a/lib/ci_helper/cli.rb b/lib/ci_helper/cli.rb index 0a98b09..9a4f2bb 100644 --- a/lib/ci_helper/cli.rb +++ b/lib/ci_helper/cli.rb @@ -26,13 +26,14 @@ def prepare! end def parse_options_from(args) - args.each_slice(2).with_object({}) do |args, options| - key = Tools::Inflector.instance.underscore(args.first.split("--").last) - value = args[1] || "" - raise Error, "Not valid options" if key.empty? - - options[key.to_sym] = value - end + args + .slice_when { |_el_before, el_after| el_after.start_with?("--") } + .each_with_object({}) do |commands, options| + key = Tools::Inflector.instance.underscore(commands.shift.split("--").last) + raise "Invalid options" if key.empty? + value = commands.size <= 1 ? commands.first : commands + options[key.to_sym] = value || "" + end end def perform_command! diff --git a/lib/ci_helper/commands.rb b/lib/ci_helper/commands.rb index 5fe7b0b..19e24a6 100644 --- a/lib/ci_helper/commands.rb +++ b/lib/ci_helper/commands.rb @@ -60,6 +60,9 @@ def boolean_option(key) def plural_option(key) return [] unless options.key?(key) + value = options[key] + return value if value.is_a?(Array) + options[key].split(",") end diff --git a/lib/ci_helper/version.rb b/lib/ci_helper/version.rb index 4745396..76e9cee 100644 --- a/lib/ci_helper/version.rb +++ b/lib/ci_helper/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CIHelper - VERSION = "0.4.1" + VERSION = "0.4.2" end diff --git a/spec/ci_helper/cli_spec.rb b/spec/ci_helper/cli_spec.rb index 03eecf5..6cd3820 100644 --- a/spec/ci_helper/cli_spec.rb +++ b/spec/ci_helper/cli_spec.rb @@ -30,7 +30,7 @@ let(:args) { [command_class_name, ""] } it "raises error" do - expect { described_class.run!(args) }.to raise_error("Not valid options") + expect { described_class.run!(args) }.to raise_error("Invalid options") end end @@ -46,6 +46,18 @@ end end + context "with array in flag arguments" do + let(:args) { [command_class_name, "--ignored-advisories", "kek", "pek"] } + + let(:expected_command) { "bundle exec bundler-audit check --update --ignore kek pek" } + + it "properly parses this option" do + expect(client_response).to eq(0) + expect(popen_executed_commands.size).to eq(1) + expect(popen_executed_commands.first).to eq(expected_command) + end + end + context "with bad thread exit code" do let(:process_value_exit_status) { 1 } let(:raised_error_message) do