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

Allow --nodes to be declared multiple times #103

wants to merge 1 commit into from

Conversation

cyberious
Copy link
Contributor

  • Allow for the user to declare --nodes multiple times along a cli and merge them into a single array, previously it would allow for last nodes declaration to win and miss any previous calls on cli

@cyberious
Copy link
Contributor Author

Resolves #100

lib/bolt/cli.rb Outdated
@@ -109,7 +109,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] = [] unless results[:nodes]
results[:nodes] = results[:nodes] + parse_nodes(nodes)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could cause a regression on uniqness as implemented in #96.

A more idiomatic ruby would be to:

results[:nodes] ||= []
results[:nodes] += parse_nodes(nodes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem would be you are assigning the result a nil list if not parsed again, so if it fails the last parse it will than give an empty list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also at the point of parsing the results[:nodes] would be nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also now that I am looking more, any reason not to switch to a struct style options parser pattern?

@cyberious
Copy link
Contributor Author

modified to have the options default to empty node list and validate that it is indeed not empty or fail accordingly

@cyberious
Copy link
Contributor Author

I will get back to fix my whitespace issues from my IDE but syntactic review and will goback on other

lib/bolt/cli.rb Outdated
parsed = parse_nodes(nodes)
if parsed
results[:nodes] += parsed
end
Copy link
Contributor

Choose a reason for hiding this comment

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

If we pass --nodes a --nodes a then we'll get duplicates, which would regress on 555b4ed. Also parse_nodes always returns an array (possible empty), so checking if parsed isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, but we are ensuring Uniq in a secondary PR that would do away with that is a separate issue can and can exist even without the secondary nodes flag.

@joshcooper
Copy link
Contributor

Thanks @cyberious! Can you squash your commits and resolve conflicts?

@cyberious
Copy link
Contributor Author

Squashed and rebased

@@ -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 more,bars])
expect(cli.parse).to include(nodes: %w[foo bar more bars])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the same node name to both --nodes flags to verify the uniqueness is working?

@@ -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

@joshcooper joshcooper added the Blocked Work blocked by other issues or PRs. label Oct 24, 2017
@joshcooper
Copy link
Contributor

Thanks @cyberious. One minor nit, it looks like your commit message has your work email address, but our CLA system only knows about your neoknght email address. Could you reset the commit author to your personal email?

- Allow for the user to declare --nodes multiple times along a cli and merge them
  into a single array, previously it would allow for last nodes declaration to win and miss any previous
  calls on cli

- Ensure we are still having a uniq list after parsing nodes each pass

- As we now take nodes multiple times we need to ensure we are still getting a unique list after we have appended
  to the original list of items, previously this was on a single pass of nodes
@cyberious
Copy link
Contributor Author

Updated to my personal

@puppetcla
Copy link

CLA signed by all contributors.

@joshcooper joshcooper removed the Blocked Work blocked by other issues or PRs. label Oct 26, 2017
@cyberious
Copy link
Contributor Author

Had to take a double check, showed closed and not merged... not sure what is up with github on this one.

@cyberious cyberious deleted the 100 branch October 26, 2017 16:38
@joshcooper
Copy link
Contributor

Thanks @cyberious! I updated the commit message to reference the JIRA ticket and merged in 4b2f043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants