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

Improve the shell completion api #8346

Merged
merged 1 commit into from
Nov 17, 2020

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Nov 14, 2020

One main advantage of the new shell completion logic is that
we can easly parse flags and adjust based on the given flags
the suggestions. For example some commands accept the
--latest flag only if no arguments are given.

This commit implements this logic in a simple maintainable way
since it reuses the already existing Args function in the
cmd struct.

I also refactored the getXXX function to match based on the
namei/id which could speed up the shell completion with many
containers, images, etc...

I also added the degraded status to the valid pod status
filters which was implemented in #8081.

@Luap99
Copy link
Member Author

Luap99 commented Nov 14, 2020

Basically typing podman start --latest [TAB] won't recommend container names while podman start [TAB] does.
This applies to all command which are using a Args function.

@rhatdan
Copy link
Member

rhatdan commented Nov 15, 2020

LGTM
/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, rhatdan

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

The pull request process is described 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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 15, 2020
@rhatdan
Copy link
Member

rhatdan commented Nov 15, 2020

@edsantiago PTAL
@containers/podman-maintainers PTAL

@Luap99
Copy link
Member Author

Luap99 commented Nov 15, 2020

I pushed a small update to handle the ExactArgs(2) or MinimumNArgs(2) functions correct. Otherwise podman cp [TAB] would have failed.

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

The refactoring LGTM - I'm finding situations where it doesn't work as I expected (podman top, podman container inspect -l) but it's still sooooo much better than what we had before. This can be refined over time. Thanks for your initiative in taking this on.

Two very minor suggestions, left up to your discretion.

cmd/podman/common/completion.go Outdated Show resolved Hide resolved
cmd/podman/common/completion.go Outdated Show resolved Hide resolved
One main advantage of the new shell completion logic is that
we can easly parse flags and adjust based on the given flags
the suggestions. For example some commands accept the
`--latest` flag only if no arguments are given.

This commit implements this logic in a simple maintainable way
since it reuses the already existing `Args` function in the
cmd struct.

I also refactored the `getXXX` function to match based on the
namei/id which could speed up the shell completion with many
containers, images, etc...

I also added the degraded status to the valid pod status
filters which was implemented in containers#8081.

Signed-off-by: Paul Holzinger <[email protected]>
@Luap99
Copy link
Member Author

Luap99 commented Nov 16, 2020

@edsantiago Updated. My error parsing didn't really work as expected. I have to clean the differences in the error message first. I thought %s could handle that.

@Luap99
Copy link
Member Author

Luap99 commented Nov 16, 2020

Not all commands use a meaningful Args function. e.g. podman top

I have to go through them one by one to see were I can improve this.

@edsantiago
Copy link
Member

Yes, that makes sense, and it can be fixed over time. No rush, this is already very helpful.

@edsantiago
Copy link
Member

The tight coupling to (and massaging of) cobra messages bothers me a little, but I can't think of a better way to do it. On the whole this LGTM but I'd like confirmation review from at least one more @containers/podman-maintainers team member.

@rhatdan
Copy link
Member

rhatdan commented Nov 17, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2020
@openshift-merge-robot openshift-merge-robot merged commit d30f9ae into containers:master Nov 17, 2020
@Luap99 Luap99 deleted the shell-completion branch November 19, 2020 20:33
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants