Skip to content

Commit 5f82373

Browse files
Support multiple args delimited by space (#8)
1 parent 70d91f4 commit 5f82373

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ RSpec/EmptyLineAfterHook:
1414
Naming/FileName:
1515
Exclude:
1616
- lib/ci-helper.rb
17+
18+
Style/HashConversion:
19+
Exclude:
20+
- spec/**/*_spec.rb

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ A command can accept list of options (parameters). Option values are passed thro
3131
For example, the BundlerAudit command accepts the ignored_advisories option
3232
You can set a value of this option by setting the flag `--ignored-advisories ignored-advisory`.
3333
It should be noted that all hyphens in flag names are automatically replaced with underscores.
34+
If command accepts array as option's value, you can separate values with either commas or spaces.
3435
```bash
35-
$ ci-helper BundlerAudit --ignored-advisories first,second
36+
$ ci-helper BundlerAudit --ignored-advisories first,second # Valid
37+
$ ci-helper BundlerAudit --ignored-advisories first second # Valid too!
3638
```
3739

3840
List of available commands:

lib/ci_helper/cli.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ def prepare!
2626
end
2727

2828
def parse_options_from(args)
29-
args.each_slice(2).with_object({}) do |args, options|
30-
key = Tools::Inflector.instance.underscore(args.first.split("--").last)
31-
value = args[1] || ""
32-
raise Error, "Not valid options" if key.empty?
33-
34-
options[key.to_sym] = value
35-
end
29+
args
30+
.slice_when { |_el_before, el_after| el_after.start_with?("--") }
31+
.each_with_object({}) do |commands, options|
32+
key = Tools::Inflector.instance.underscore(commands.shift.split("--").last)
33+
raise "Invalid options" if key.empty?
34+
value = commands.size <= 1 ? commands.first : commands
35+
options[key.to_sym] = value || ""
36+
end
3637
end
3738

3839
def perform_command!

lib/ci_helper/commands.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def boolean_option(key)
6060

6161
def plural_option(key)
6262
return [] unless options.key?(key)
63+
value = options[key]
64+
return value if value.is_a?(Array)
65+
6366
options[key].split(",")
6467
end
6568

lib/ci_helper/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CIHelper
4-
VERSION = "0.4.1"
4+
VERSION = "0.4.2"
55
end

spec/ci_helper/cli_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
let(:args) { [command_class_name, ""] }
3131

3232
it "raises error" do
33-
expect { described_class.run!(args) }.to raise_error("Not valid options")
33+
expect { described_class.run!(args) }.to raise_error("Invalid options")
3434
end
3535
end
3636

@@ -46,6 +46,18 @@
4646
end
4747
end
4848

49+
context "with array in flag arguments" do
50+
let(:args) { [command_class_name, "--ignored-advisories", "kek", "pek"] }
51+
52+
let(:expected_command) { "bundle exec bundler-audit check --update --ignore kek pek" }
53+
54+
it "properly parses this option" do
55+
expect(client_response).to eq(0)
56+
expect(popen_executed_commands.size).to eq(1)
57+
expect(popen_executed_commands.first).to eq(expected_command)
58+
end
59+
end
60+
4961
context "with bad thread exit code" do
5062
let(:process_value_exit_status) { 1 }
5163
let(:raised_error_message) do

0 commit comments

Comments
 (0)