Minor feature: Add -a/--all option to brl which to list all strata that provide a given binary#212
Minor feature: Add -a/--all option to brl which to list all strata that provide a given binary#212cptpcrd wants to merge 1 commit intobedrocklinux:masterfrom
brl which to list all strata that provide a given binary#212Conversation
|
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. |
| } | ||
|
|
||
| which_bin_all() ( | ||
| min_args "${#}" "1" |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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 -randwhich, but to me this feels like a missing feature.In a nutshell, here's what I'm aiming for:
This PR adds a
-a/--alloption tobrl whichwhich does this.Notes
which_fileif any of the arguments contain a/. I can implement that too.