|
5 | 5 | "fmt" |
6 | 6 | "os" |
7 | 7 | "path/filepath" |
| 8 | + "runtime" |
| 9 | + "strings" |
8 | 10 |
|
9 | 11 | "github.com/docker/buildx/commands" |
10 | 12 | controllererrors "github.com/docker/buildx/controller/errdefs" |
@@ -43,6 +45,30 @@ func runStandalone(cmd *command.DockerCli) error { |
43 | 45 | defer flushMetrics(cmd) |
44 | 46 |
|
45 | 47 | executable := os.Args[0] |
| 48 | + if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { |
| 49 | + // Note that we're cutting some corners here. The intent here |
| 50 | + // is for both "usage" and shell-completion scripts to use the |
| 51 | + // name of the executable with its actual (lower, upper) case. |
| 52 | + // However, on case-insensitive platforms, the user can invoke |
| 53 | + // the executable using any case (e.g., "bUiLdX"). |
| 54 | + // |
| 55 | + // Unfortunately, neither [os.Executable] nor [os.Stat] provide |
| 56 | + // this information, and the "correct" solution would be to use |
| 57 | + // [os.File.Readdirnames], which is a rather heavy hammer to use |
| 58 | + // just for this. |
| 59 | + // |
| 60 | + // So, on macOS and Windows (usually case-insensitive platforms) |
| 61 | + // we assume the executable is always lower-case, but it's worth |
| 62 | + // noting that there's a corner-case to this corner-case; both |
| 63 | + // Windows and macOS can be configured to use a case-sensitive |
| 64 | + // filesystem (on Windows, this can be configured per-Directory). |
| 65 | + // If that is the case, and the executable is not lowercase, the |
| 66 | + // generated shell-completion script will be invalid. |
| 67 | + // |
| 68 | + // Let's assume that's not the case, and that the user did not |
| 69 | + // rename the executable to anything uppercase. |
| 70 | + executable = strings.ToLower(executable) |
| 71 | + } |
46 | 72 | rootCmd := commands.NewRootCmd(filepath.Base(executable), false, cmd) |
47 | 73 | return rootCmd.Execute() |
48 | 74 | } |
|
0 commit comments