Skip to content
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

Remove .exe suffix if any in completion #24966

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

silver886
Copy link
Contributor

In shell completion, there is .exe suffix on Windows and this break several shells.

Relates to #16499.
It seems didn't fix at the time but waiting for a fix in cobra.

Fixed a bug that prevents shell completion on Windows under some circumstances.

Copy link
Contributor

openshift-ci bot commented Jan 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: silver886
Once this PR has been reviewed and has the lgtm label, please assign giuseppe for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, please add the description from the PR also to the commit message.

It would also be a good idea to have some form of test, I think podman --help might be enough to run on windows and check the Usage string?
@l0rd Any idea where this could be added?

@@ -62,7 +62,7 @@ Options:

var (
rootCmd = &cobra.Command{
Use: filepath.Base(os.Args[0]) + " [options]",
Use: strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe") + " [options]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here why .exe is trimmed and add a link to the issue.
If the line is moved or edited again it may no longer be easy to find in the git history.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment and links to issue and pr are added.
I also added description to the commit message.

@baude
Copy link
Member

baude commented Jan 8, 2025

LGTM other than the comment

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks please also squash the commits as this is one change.

@l0rd
Copy link
Member

l0rd commented Jan 9, 2025

It would also be a good idea to have some form of test, I think podman --help might be enough to run on windows and check the Usage string? @l0rd Any idea where this could be added?

@Luap99 do you mean something similar to test/system/600-completion.bats but simpler and that runs on windows? I would probably try to add it in test/e2e.

I have manually tested this PR, and completion works fine on Powershell for podman, with and without .exe suffix.

One minor comment:

It was waiting for a fix in cobra upstream, but since that has not happened yet...

I may be missing something but it looks like the cobra issue has been fixed and that's a Podman specific issue now (kubectl completion for instance works fine with and without .exe). Maybe it would be helpful to document why we are not using the hardcoded podman and we need os.Args[0] instead?

@Luap99
Copy link
Member

Luap99 commented Jan 10, 2025

It would also be a good idea to have some form of test, I think podman --help might be enough to run on windows and check the Usage string? @l0rd Any idea where this could be added?

@Luap99 do you mean something similar to test/system/600-completion.bats but simpler and that runs on windows? I would probably try to add it in test/e2e.

No that test is useless for a bug like this it test actuall completion function that are the same on all platforms so there is no need to duplicate that.
As I said above you should be able to extract that base command name from the podman --help usage string which should be more than enough to ensure the command name is sane.

Maybe it would be helpful to document why we are not using the hardcoded podman and we need os.Args[0] instead?

Because we use podman-remote as well for the same cli.

@l0rd
Copy link
Member

l0rd commented Jan 10, 2025

@Luap99 oh ok that's clear now, thanks. Then a new test pkg/machine/e2e/help_test.go should work (@silver886 you can get inspiration from pkg/machine/e2e/info_test.go).

@silver886
Copy link
Contributor Author

silver886 commented Jan 10, 2025

@l0rd am I looking at the right document for unit testing?
https://github.com/containers/podman/blob/main/test/README.md#unittest-for-testutils

It seems like make localunit doesn't run unit tests for pkg/machine/e2e as it

Will skip:
  ./hack/podman-registry-go
  ./pkg/bindings/images
  ./pkg/bindings/test
  ./pkg/machine/e2e
  ./test/e2e

And in the pipeline, that's the only command for unit test.
https://cirrus-ci.com/task/5707589457018880?logs=main#L32

@l0rd
Copy link
Member

l0rd commented Jan 10, 2025

@silver886 no, that's not the correct documentation. That's hard to find, but the proper documentation for running podman remote e2e tests is here: pkg/machine/e2e/README.md.

@silver886 silver886 force-pushed the patch-2 branch 2 times, most recently from 604cf2e to 78b109e Compare January 11, 2025 03:04
@silver886
Copy link
Contributor Author

@l0rd @Luap99 I added the unit test and it passed on Windows.

Copy link
Member

@l0rd l0rd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silver886 thank you very much for the update and the tests. It looks great 👏. We are almost there. I have provided some suggestions, please have a look.

. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman completion powershell", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command name is usually used in the description. If we add more podman help tests, they will be added here.

Suggested change
var _ = Describe("podman completion powershell", func() {
var _ = Describe("podman help", func() {


var _ = Describe("podman completion powershell", func() {

It("completion powershell", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will be run on Linux and macOS too. We may specify that this is a Windows only tests so that it doesn't run there but I won't do that as I think there is value in testing it on all OSes.
Instead, I would change the description and adapt the test to ensure that the command matches the string podman or podman-remote. I would also add a comment explaining why we are doing this test on the basic command (because command completion doesn't work otherwise) anda link to the issue you are fixing.

Suggested change
It("completion powershell", func() {
It("podman usage base command is podman or podman-remote, without extension", func() {

}

func (i *helpMachine) buildCmd(m *machineTestBuilder) []string {
cmd := []string{"machine", "info", "--help"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd := []string{"machine", "info", "--help"}
cmd := []string{"help"}

Comment on lines 68 to 70
//
// It was waiting for a fix in cobra upstream, but since that has not happened yet,
// a fix was implemented in [#24966](https://github.com/containers/podman/pull/24966).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is necessary and anyway the cobra upstream issue has been fixed.

Suggested change
//
// It was waiting for a fix in cobra upstream, but since that has not happened yet,
// a fix was implemented in [#24966](https://github.com/containers/podman/pull/24966).

@silver886
Copy link
Contributor Author

@l0rd thank you. I have a terrible sense of naming.

@l0rd
Copy link
Member

l0rd commented Jan 14, 2025

@l0rd thank you. I have a terrible sense of naming.

Eh eh, naming is hard :-)

Fantastic. Can you please squash the 3 commits into a single one and force push? And please make sure to sign your commit so that the DCO check is passing.

Signed-off-by: Leo Liu <[email protected]>

Add comment

In shell completion, there is `.exe` suffix on Windows and this does not provide same experience across platforms, containers#16499

Signed-off-by: Leo Liu <[email protected]>

Create unit test for `.exe` suffix removal

Signed-off-by: Leo Liu <[email protected]>

Update comments

Signed-off-by: Leo Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants