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

Prefix bash functions with root command name #643

Merged
merged 2 commits into from
Feb 28, 2018
Merged

Prefix bash functions with root command name #643

merged 2 commits into from
Feb 28, 2018

Conversation

johnmccabe
Copy link
Contributor

Prior to this PR the autocomplete bash functions were being prefixed with the root command name, but references to those functions from subcommands were having the subcommands prefixed instead - causing the function lookups to fail and error out.

As spotted by @janetkuo in kubernetes/kubernetes#60517:

kubectl create -f [Tab] failed with the following message: kubectl
create -f __create_handle_filename_extension_flag: command not found

in this case the function being invoked should be:

__kubectl_handle_filename_extension_flag

This PR switches to using cmd.Root().Name() in order to use the root rather than subcommand.

kubectl_autocomplete

Prior to this commit the autocomplete bash functions were being prefixed
with the root command name, but references to those functions from
subcommands were having the subcommands prefixed instead - causing the
function lookups to fail and error out.

For example (as observed in kubernetes/kubernetes#60517):

kubectl create -f [Tab] failed with the following message: kubectl
create -f __create_handle_filename_extension_flag: command not found

in this case the function being invoked should be __kubectl_handle_filename_extension_flag

Signed-off-by: John McCabe <john@johnmccabe.net>
@eparis
Copy link
Collaborator

eparis commented Feb 28, 2018

Should we add a test to make sure that subdir completions will always call the rootdir handler?

@johnmccabe
Copy link
Contributor Author

Sounds reasonable

This commit adds two regex based tests to ensure that the handle
filename extension and handle subdirs in dir functions are prefixed by
the root command when present in subcommands.

Previously they had been prefixed incorrectly with the subcommand name.

Signed-off-by: John McCabe <john@johnmccabe.net>
@johnmccabe
Copy link
Contributor Author

@eparis added some tests for subcommands, that look ok to you

@eparis eparis merged commit 6644d46 into spf13:master Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants