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

cmd/list: Constrain -lrt options to formulae #10133

Merged

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Dec 24, 2020

  • 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 typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run 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 on brew list -l was Error: 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!

- 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`.
```
@BrewTestBot
Copy link
Member

Review period will end on 2020-12-25 at 13:40:07 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 24, 2020
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

👏🏻 ❤️

@Rylan12
Copy link
Member

Rylan12 commented Dec 24, 2020

FYI @MikeMcQuaid you added these depends_on lines in #9035 and then promptly removed them (two hours later) in #9038. Just want to make sure that we don't re-introduce any issues that then cause this to be removed once again.

Based on glancing at the issues, if brew list -l fails (because it required --formula) and brew list <formula> --versions works, I think both issues have been solved.

Edit: it looks like #9038 just removed the depends_on line from more options than it needed to. I think this is good.

@issyl0
Copy link
Member Author

issyl0 commented Dec 24, 2020

@Rylan12 Both work with these changes:

➜ brew list -l
[...]
Error: Invalid usage: `-l` cannot be passed without `--formula`.
➜ brew list ruby --versions
ruby 2.7.2

Copy link
Member

@Rylan12 Rylan12 left a 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!

Comment on lines 536 to 537
arg1 = "--#{arg1.tr("_", "-")}"
arg2 = "--#{arg2.tr("_", "-")}"
arg1 = dashes(arg1) + arg1.tr("_", "-")
arg2 = dashes(arg2) + arg2.tr("_", "-")
Copy link
Member

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

Copy link
Member

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

raise OptionConflictError, violations.map(&method(:name_to_option)) unless select_cli_arg

Maybe it doesn't do what I thought...

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@Rylan12 Rylan12 Dec 24, 2020

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

This doesn't fix the issue that @reitermarkus raised, though.

Copy link
Member Author

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!

Copy link
Member

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

Copy link
Member

@Rylan12 Rylan12 left a 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!

Library/Homebrew/cli/parser.rb Outdated Show resolved Hide resolved
- 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]>
@issyl0 issyl0 force-pushed the constrain-brew-list-lrt-options-to-formulae-only branch from a20e600 to 531cae4 Compare December 24, 2020 16:53
@issyl0
Copy link
Member Author

issyl0 commented Dec 24, 2020

No problem, I should have noticed that line was getting a bit long. I fixed it in a different way.

@issyl0
Copy link
Member Author

issyl0 commented Dec 24, 2020

Given this fixes a bug, I'm adding the critical label. 🟥

@issyl0 issyl0 added the critical Critical change which should be shipped as soon as possible. label Dec 24, 2020
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 24, 2020
@BrewTestBot
Copy link
Member

BrewTestBot commented Dec 24, 2020

Review period ended.

@issyl0 issyl0 enabled auto-merge December 24, 2020 17:10
@issyl0 issyl0 merged commit 2424e58 into Homebrew:master Dec 24, 2020
@issyl0 issyl0 deleted the constrain-brew-list-lrt-options-to-formulae-only branch December 24, 2020 18:14
@MikeMcQuaid
Copy link
Member

FYI @MikeMcQuaid you added these depends_on lines in #9035 and then promptly removed them (two hours later) in #9038. Just want to make sure that we don't re-introduce any issues that then cause this to be removed once again.

@Rylan12 that was before disabling so should be fine 👍🏻

Thanks @issyl0!

@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Jan 26, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

brew list -l produces short output for casks, doesn't print totals as claimed in help
5 participants