-
Notifications
You must be signed in to change notification settings - Fork 68
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
Minor feature: Add -a/--all option to brl which
to list all strata that provide a given binary
#212
base: master
Are you sure you want to change the base?
Conversation
A number of people have shown interest in something like this over the years (e.g. https://gist.github.com/NICHOLAS85/a01d5f64744e4924ec0a5d5fd112cbc1). I've been hesitant in the past, but at some point I should probably just accept the demand for this outweighs the associated complexity. In the past, another option I've considered as an alternative to this would be a new
However, in practice, I expect the vast majority of use cases to be equivalent to So I guess we'll go with
|
Prints the list of strata in which the given binary can be found.
60821a2
to
0ac59f6
Compare
@paradigm I've pushed changes that should address most of your concerns, though I have a few of my own. I'll leave comments at relevant points. |
@@ -67,6 +68,19 @@ which_bin() { | |||
done | |||
} | |||
|
|||
which_bin_all() ( | |||
min_args "${#}" "1" |
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 didn't test this before pushing, and it appears min_args
doesn't work reliably from inside functions. Currently, this happens, and it's not immediately obvious to me how to fix it:
$ brl which -ab
ERROR: Insufficient arguments, see `--help`.
ERROR: Unexpected error occurred.
which_bin_all() ( | ||
min_args "${#}" "1" | ||
|
||
while [ -n "${1:-}" ]; do |
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 normal brl which
interface doesn't really work properly with -a
. For example, this is very ambiguous:
$ brl which -a cmake git
void
void-musl
arch
Some of the formats that leapt to mind include:
$ brl which -a cmake git
void: cmake
void-musl: cmake
arch: git
$ brl which -a cmake git
cmake: void
cmake: void-musl
git: arch
$ brl which -a cmake git
cmake: void void-musl
git: arch
$ brl which -a cmake git
void: cmake git
void-musl: cmake
arch: git
I'm not really sure which is best.
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.
Personally
$ brl which -a cmake git
void: cmake git
void-musl: cmake
arch: git
makes the most sense to me, as this quickly shows what has what, while still having a per distro view.
|
||
while [ -n "${1:-}" ]; do | ||
for stratum in $(list_strata); do | ||
if path="$(strat -r "${stratum}" /bedrock/libexec/busybox which "$1" 2>/dev/null)"; then |
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 can add handling for "file/binary not found" both here and in which_file_all
, but what should be the behavior? Something like this?
$ brl which -a git 0ad cmake
arch: git
WARNING: 0ad not found in any strata
void: cmake
# exit with status 1
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 don't think it makes much sense to phrase it as a warning, as it's really just the absence of something. Perhaps something closer to just 0ad not found in any strata
?
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.
That would probably depend on the exact format; see above. e.g. for some it could be 0ad not found
; for others 0ad: not found
might make more sense. Colorization might help too.
12e1061
to
524beae
Compare
Rationale
Sometimes, when on a Bedrock system, I find myself wondering "which strata do I have X installed in?" What I'd like is a combination of the functionality of
brl which -b
(which prints the stratum that provides a given binary) andwhich -a
(with GNU coreutils, this prints all the locations in which the given program can be found). I could probably implement this with a quick one-liner usingstrat -r
andwhich
, but to me this feels like a missing feature.In a nutshell, here's what I'm aiming for:
This PR adds a
-a
/--all
option tobrl which
which does this.Notes
which_file
if any of the arguments contain a/
. I can implement that too.