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. |
- 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: |
| arg1 = "--#{arg1.tr("_", "-")}" | ||
| arg2 = "--#{arg2.tr("_", "-")}" | ||
| arg1 = dashes(arg1) + arg1.tr("_", "-") | ||
| arg2 = dashes(arg2) + arg2.tr("_", "-") |
There was a problem hiding this comment.
You might be able to use the name_to_option method here
There was a problem hiding this comment.
Hmm, wait. It looks like this is already being called...
brew/Library/Homebrew/cli/parser.rb
Line 455 in 27afcf5
Maybe it doesn't do what I thought...
There was a problem hiding this comment.
The tr("_", "-") part is not correct for e.g. --screen_saverdir.
There was a problem hiding this comment.
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.
@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 raises)
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
endThis doesn't fix the issue that @reitermarkus raised, though.
There was a problem hiding this comment.
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.
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
Rylan12
left a comment
There was a problem hiding this comment.
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 <rslpolster@gmail.com>
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 stylewith your changes locally?brew typecheckwith your changes locally?brew testswith your changes locally?brew manlocally 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
--formulaoption onbrew list -lwasError: 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!