From a91aa36367316ea24a07fde15689b7d738fc2cdb Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Tue, 7 Jan 2025 22:24:32 -0800 Subject: [PATCH] Remove `.exe` suffix if any Signed-off-by: Leo Liu Add comment In shell completion, there is `.exe` suffix on Windows and this does not provide same experience across platforms, #16499 Signed-off-by: Leo Liu Create unit test for `.exe` suffix removal Signed-off-by: Leo Liu <11664880+silver886@users.noreply.github.com> Update comments Signed-off-by: Leo Liu <11664880+silver886@users.noreply.github.com> --- cmd/podman/root.go | 5 ++++- pkg/machine/e2e/config_help_test.go | 11 +++++++++++ pkg/machine/e2e/help_test.go | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pkg/machine/e2e/config_help_test.go create mode 100644 pkg/machine/e2e/help_test.go diff --git a/cmd/podman/root.go b/cmd/podman/root.go index e48b497d77..f80b906ae5 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -62,7 +62,10 @@ Options: var ( rootCmd = &cobra.Command{ - Use: filepath.Base(os.Args[0]) + " [options]", + // In shell completion, there is `.exe` suffix on Windows. + // This does not provide the same experience across platforms + // and was mentioned in [#16499](https://github.com/containers/podman/issues/16499). + Use: strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe") + " [options]", Long: "Manage pods, containers and images", SilenceUsage: true, SilenceErrors: true, diff --git a/pkg/machine/e2e/config_help_test.go b/pkg/machine/e2e/config_help_test.go new file mode 100644 index 0000000000..071653c82a --- /dev/null +++ b/pkg/machine/e2e/config_help_test.go @@ -0,0 +1,11 @@ +package e2e_test + +type helpMachine struct { + cmd []string +} + +func (i *helpMachine) buildCmd(m *machineTestBuilder) []string { + cmd := []string{"help"} + i.cmd = cmd + return cmd +} diff --git a/pkg/machine/e2e/help_test.go b/pkg/machine/e2e/help_test.go new file mode 100644 index 0000000000..48f653c5ca --- /dev/null +++ b/pkg/machine/e2e/help_test.go @@ -0,0 +1,23 @@ +package e2e_test + +import ( + "regexp" + "slices" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" +) + +var _ = Describe("podman help", func() { + It("podman usage base command is podman or podman-remote, without extension ", func() { + helpSession, err := mb.setCmd(new(helpMachine)).run() + Expect(err).NotTo(HaveOccurred()) + Expect(helpSession).Should(Exit(0)) + + // Verify `.exe` suffix doesn't present in the usage command string + helpMessages := helpSession.outputToStringSlice() + usageCmdIndex := slices.IndexFunc(helpMessages, func(helpMessage string) bool { return helpMessage == "Usage:" }) + 1 + Expect(regexp.MustCompile(`\w\.exe\b`).MatchString(helpMessages[usageCmdIndex])).Should(BeFalse()) + }) +})