Skip to content

Commit

Permalink
Fix argument and options order in command (#121)
Browse files Browse the repository at this point in the history
* Fix argument and options orderin command

* Bump version
  • Loading branch information
tubaxenor authored Sep 24, 2024
1 parent 7020ced commit 9f44865
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.13.0
4.14.0
18 changes: 14 additions & 4 deletions lib/buildkite/pipelines/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,24 @@ def run(exception: false)

def to_a
command = [BIN_PATH, @command, @subcommand]
command.concat(@options.to_a.flatten)
command.concat(@args)
# The `artifact` command has a different order of options and arguments:
# `buildkite-agent artifact upload [options] <file> <destination>`,
# `buildkite-agent artifact download [options] <file>`,
# `buildkite-agent artifact search [options] <query>`,
# so we need to handle it separately.
if @command == 'artifact'
command.concat(@options.to_a.flatten)
command.concat(@args)
else
command.concat(@args)
command.concat(@options.to_a.flatten)
end
end

def extract_options(args)
return {} unless args.first.is_a?(Hash)
return {} unless args.last.is_a?(Hash)

args.shift.tap do |options|
args.pop.tap do |options|
options.transform_keys! do |key|
"--#{key.to_s.tr('_', '-')}"
end
Expand Down
6 changes: 3 additions & 3 deletions spec/buildkite/pipelines/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
let(:subcommand) { :upload }
let(:options) { { foo_key: :foo_value, bar_key: :bar_value } }
let(:args) { [Pathname.new('/path/to/foo'), Pathname.new('/path/to/bar')] }
let(:instance) { described_class.new(command, subcommand, options, *args) }
let(:instance) { described_class.new(command, subcommand, *args, options) }
let(:mock_status) { instance_double(Process::Status, success?: true) }

before do
Expand All @@ -84,12 +84,12 @@
Buildkite::Pipelines::Command::BIN_PATH,
command.to_s,
subcommand.to_s,
'/path/to/foo',
'/path/to/bar',
'--foo-key',
'foo_value',
'--bar-key',
'bar_value',
'/path/to/foo',
'/path/to/bar'
)

instance.run
Expand Down

0 comments on commit 9f44865

Please sign in to comment.