usage, completion: assume executable is always lowercase #2951
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
usage, completion: assume executable is always lowercase
When running on a case-insensitive platform / filesystem, the user
can invoke the executable using any case (e.g., "bUiLdX"). In situations
where buildx is running standalone, we use os.Args to determine the
name of the executable, and this information is used by Cobra to
print "Usage" output as well as generating the shell-completion
scripts.
Unfortunately, neither os.Executable nor os.Stat provide information
about the actual name of the executable, and the "correct" solution would
be to use os.File.Readdirnames, which is a rather heavy hammer to use
just for this.
This patch assumes the executable to be named lowercase, regardless of
how it's invoked, on macOS and Windows (usually case-insensitive platforms).
It's worth noting that there's a corner-case to this corner-case; both
Windows and macOS can be configured to use a case-sensitive filesystem
(on Windows, this can be configured per-Directory). If that is the case,
and the executable is not lowercase, the generated shell-completion script
will be invalid.
Let's assume that's not the case, and that the user did not rename the
executable to anything uppercase.
Before this patch:
With this patch applied: