-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
cmd/list: Constrain -lrt
options to formulae
#10133
cmd/list: Constrain -lrt
options to formulae
#10133
Conversation
- These are documented as only working on formulae, but users expect the same options (long format, reverse order or sort by modified time) to be passed to both formulae and casks in the default `brew list`. The output looks weird as they're not. Hence, constrain these to be `--formula`-only. - This was added originally in 5adb76a, but then disappeared.
- This avoids error messages like: ``` ➜ brew list -l Error: Invalid usage: `--l` cannot be passed without `--formula`. ```
Review period will end on 2020-12-25 at 13:40:07 UTC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏻 ❤️
- This reads nicer (to me).
FYI @MikeMcQuaid you added these Based on glancing at the issues, if Edit: it looks like #9038 just removed the |
@Rylan12 Both work with these changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me too!
Library/Homebrew/cli/parser.rb
Outdated
arg1 = "--#{arg1.tr("_", "-")}" | ||
arg2 = "--#{arg2.tr("_", "-")}" | ||
arg1 = dashes(arg1) + arg1.tr("_", "-") | ||
arg2 = dashes(arg2) + arg2.tr("_", "-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to use the name_to_option
method here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, wait. It looks like this is already being called...
brew/Library/Homebrew/cli/parser.rb
Line 455 in 27afcf5
raise OptionConflictError, violations.map(&method(:name_to_option)) unless select_cli_arg |
Maybe it doesn't do what I thought...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tr("_", "-")
part is not correct for e.g. --screen_saverdir
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. That must have been broken before now. Can you give me a full example command that uses that so I can try to figure it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@issyl0 I think this will work for the check_constraints
method which will remove the need for this:
I just changed primary
and secondary
to name_to_option(primary)
and name_to_option(secondary)
in the raise
s)
def check_constraints
@constraints.each do |primary, secondary, constraint_type|
primary_passed = option_passed?(primary)
secondary_passed = option_passed?(secondary)
if :mandatory.equal?(constraint_type) && primary_passed && !secondary_passed
raise OptionConstraintError.new(name_to_option(primary), name_to_option(secondary))
end
raise OptionConstraintError.new(name_to_option(primary), name_to_option(secondary), missing: true) if secondary_passed && !primary_passed
end
end
This doesn't fix the issue that @reitermarkus raised, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue @reitermarkus raised was pre-existing as I didn't change any of the code for the arg.tr("_", "-")
stuff, so we can tackle that in another PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like these are the options that will have this issue:
--input_methoddir
--internet_plugindir
--audio_unit_plugindir
--vst_plugindir
--vst3_plugindir
--screen_saverdir
They're all cask options. We may want to check in name_to_option
to see if the option matched one of those. If so, don't do the tr
. Separate PR makes sense I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, my bad with the suggestion. Otherwise looks good!
- There's already a method on `CLI::Parser`, we don't need to hand-roll the "number of dashes" detection. Co-authored-by: Rylan Polster <[email protected]>
a20e600
to
531cae4
Compare
No problem, I should have noticed that line was getting a bit long. I fixed it in a different way. |
Given this fixes a bug, I'm adding the critical label. 🟥 |
Review period ended. |
@Rylan12 that was before disabling so should be fine 👍🏻 Thanks @issyl0! |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?brew man
locally and committed any changes?Fixes brew list -l produces short output for casks, doesn't print totals as claimed in help #10116 (part two).
These are documented as only working on formulae, but users expect the same options (long format, reverse order or sort by modified time) to be passed to both formulae and casks in the default
brew list
. The output looks weird as they're not. Hence, constrain these to be--formula
-only.This was added originally in 5adb76a, but disappeared later (I've not yet dug through and found why).
This also fixes the CLI parser's handling of error messages for short options (assuming they're only a single character). Before, the error messages for this missing
--formula
option onbrew list -l
wasError: Invalid usage:
--lcannot be passed without
--formula.
.I don't much like this code, but I'll revisit it later - I have to run for a 🚌 🚏 now!