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

install: Use CLI::Parser to parse args #5619

Merged
merged 9 commits into from
Jan 29, 2019

Conversation

GauthamGoli
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

#1860

@GauthamGoli GauthamGoli force-pushed the install-args branch 4 times, most recently from c17cf1d to 12eb104 Compare January 26, 2019 14:19
Library/Homebrew/cmd/install.rb Outdated Show resolved Hide resolved
@@ -317,11 +397,11 @@ def install_formula(f)
fi = FormulaInstaller.new(f)
fi.options = build_options.used_options
fi.invalid_option_names = build_options.invalid_option_names
Copy link
Member

Choose a reason for hiding this comment

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

Might be a good idea to use the build_options.invalid_option_names above instead of the formulae loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure I understand. Can you explain this more?

Copy link
Member

Choose a reason for hiding this comment

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

Sure. This is used at

invalid_option_names.each do |option|
opoo "#{formula.full_name}: this formula has no #{option} option so it will be ignored!"
end
so will never fire in future if this is added (so could be deleted). Given build_options.invalid_option_names already exists perhaps that method could be used instead, used for inspiration (or deleted):
# @private
def invalid_options
@args - @options - BuildOptions.formula_install_options
end
# @private
def invalid_option_names
invalid_options.map(&:flag).sort
end
def self.formula_install_options
@formula_install_options ||= ARGV.formula_install_option_names.map do |option_name|
Option.new option_name[2..-1]
end
end

Make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @MikeMcQuaid. Got it.

One more question.

In the existing behaviour, we ignore the invalid options passed, but that is not possible with OptionParser, as we only declare the valid options. Do we ideally want to preserve this functionality?

Copy link
Member

Choose a reason for hiding this comment

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

@GauthamGoli If we're only looking at externally passed options I think it's fine/better to error out rather than ignoring and messaging 👍

@MikeMcQuaid
Copy link
Member

Would be good to use/replace this logic:

invalid_option_names.each do |option|
opoo "#{formula.full_name}: this formula has no #{option} option so it will be ignored!"
end

@MikeMcQuaid MikeMcQuaid merged commit 618f75c into Homebrew:master Jan 29, 2019
@lock lock bot added the outdated PR was locked due to age label Feb 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants