Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --nodes to be declared multiple times #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/bolt/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ class CLI
attr_accessor :options

def initialize(argv)
@argv = argv
@options = {}
@argv = argv
@options = {
nodes: []
}

@parser = create_option_parser(@options)
end
Expand All @@ -111,7 +113,8 @@ def create_option_parser(results)
'* protocol is `ssh` by default, may be `ssh` or `winrm`',
'* port is `22` by default for SSH, `5985` for winrm (Optional)'
) do |nodes|
results[:nodes] = parse_nodes(nodes)
results[:nodes] += parse_nodes(nodes)
results[:nodes].uniq!
end
opts.on('-u', '--user USER',
"User to authenticate as (Optional)") do |user|
Expand Down Expand Up @@ -283,7 +286,7 @@ def validate(options)
"unknown argument(s) #{options[:leftovers].join(', ')}"
end

unless options[:nodes] || options[:mode] == 'plan'
unless !options[:nodes].empty? || options[:mode] == 'plan'
raise Bolt::CLIError, "option --nodes must be specified"
end

Expand Down
13 changes: 9 additions & 4 deletions spec/bolt/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
expect(cli.parse).to include(nodes: %w[foo bar])
end

it "accepts multiple nodes across multiple declarations" do
cli = Bolt::CLI.new(%w[command run --nodes foo,bar --nodes bar,more,bars])
Copy link
Contributor Author

@cyberious cyberious Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshcooper just added bar in second location to ensure uniq still works

expect(cli.parse).to include(nodes: %w[foo bar more bars])
end

it "reads from stdin when --nodes is '-'" do
nodes = <<NODES
foo
Expand Down Expand Up @@ -255,7 +260,7 @@
cli = Bolt::CLI.new(%w[plan run my::plan kj=2hv iuhg=iube 2whf=lcv
--modulepath .])
result = cli.parse
expect(result[:task_options]).to eq('kj' => '2hv',
expect(result[:task_options]).to eq('kj' => '2hv',
'iuhg' => 'iube',
'2whf' => 'lcv')
end
Expand All @@ -265,7 +270,7 @@
cli = Bolt::CLI.new(['plan', 'run', 'my::plan', '--params', json_args,
'--modulepath', '.'])
result = cli.parse
expect(result[:task_options]).to eq('kj' => '2hv',
expect(result[:task_options]).to eq('kj' => '2hv',
'iuhg' => 'iube',
'2whf' => 'lcv')
end
Expand All @@ -292,7 +297,7 @@
cli = Bolt::CLI.new(%W[plan run my::plan --params @#{file.path}
--modulepath .])
result = cli.parse
expect(result[:task_options]).to eq('kj' => '2hv',
expect(result[:task_options]).to eq('kj' => '2hv',
'iuhg' => 'iube',
'2whf' => 'lcv')
end
Expand All @@ -313,7 +318,7 @@
cli = Bolt::CLI.new(%w[plan run my::plan --params - --modulepath .])
allow(STDIN).to receive(:read).and_return(json_args)
result = cli.parse
expect(result[:task_options]).to eq('kj' => '2hv',
expect(result[:task_options]).to eq('kj' => '2hv',
'iuhg' => 'iube',
'2whf' => 'lcv')
end
Expand Down