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/--prefix: add --installed flag #10266
Conversation
Review period will end on 2021-01-11 at 11:45:07 UTC. |
ed195a8
to
105faad
Compare
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.
Nice work so far @gromgit!
105faad
to
c39e41d
Compare
Could even consider raising a |
c39e41d
to
ec4a1f3
Compare
I'm not sure about that. "Formula not installed" is not an exceptional condition, and it's certainly not an unrecoverable one, unlike "no such formula". In fact, I can see a build script doing something like the following: #!/usr/bin/env bash
shopt -s lastpipe
set -o pipefail
deps=(abcde python@3.9 tcl-tk)
prefixes=()
# Let's see what's already installed
brew --prefix --installed "${deps[@]}" | readarray -t prefixes
for n in "${!deps[@]}"; do
if [[ -z "${prefixes[$n]}" ]]; then
# Install what's missing
brew install "${deps[$n]}"
fi
done
# Get all the prefixes again, so we can use them for real
brew --prefix --installed "${deps[@]}" | readarray -t prefixes
[...] |
It feels weird to return an non-zero status code and not say why, is my only concern. We get to define what this outputs/does as we're creating a new flag (and hiding it is only a |
ec4a1f3
to
0e1efc8
Compare
Fair enough. I've altered the output to list the missing formulae on stderr: $ brew --prefix --installed abcde python@3.9 tcl-tk
/usr/local/opt/python@3.9
Warning: The following formulae are not installed:
abcde tcl-tk
$ brew --prefix --installed abcde python@3.9 tcl-tk 2>/dev/null || echo Missing stuff
/usr/local/opt/python@3.9
Missing stuff |
I feel like at that point |
You mean like: if args.installed?
missing_formulae = formulae.reject { |f| f.opt_prefix.exist? }
.map(&:name)
return if missing_formulae.empty?
raise NotAKegError, <<~EOS
The following formulae are not installed:
#{missing_formulae.join(" ")}
EOS
end which does this: $ brew --prefix --installed abcde python@3.9 tcl-tk
/usr/local/opt/python@3.9
Error: The following formulae are not installed:
abcde tcl-tk ? I don't have a strong opinion either way, but I'd rather respect existing semantics where possible, if only to make it easier for the next person to comprehend the code. |
0e1efc8
to
50a85bf
Compare
Review period ended. |
f73cb35
to
1b72198
Compare
This changes the output for uninstalled formulae from Cellar prefix to empty string, so: ```sh $ brew --prefix abcde python@3.9 tcl-tk /usr/local/Cellar/abcde/2.9.3_1 /usr/local/opt/python@3.9 /usr/local/Cellar/tcl-tk/8.6.10 $ brew --prefix --installed abcde python@3.9 tcl-tk /usr/local/opt/python@3.9 $ ```
1b72198
to
28a8409
Compare
Thanks again @gromgit, great work here! |
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?This changes the output for uninstalled formulae from Cellar prefix to empty string, so:
Fixes #10261. I chose to print an empty string instead of not printing anything at all, because
brew --prefix
supports multiple formulae input, so this lets the user tell both visually and programmatically which formulae aren't installed.For the same reason, "not installed" still returns success as before, so that "no such formula" remains the only error conditionAfter a second think, since the switch is called--installed
, it should return failure (to indicate that not everything requested is in place) but not an error message, since it's not an exceptional condition like "no such formula":