-
Notifications
You must be signed in to change notification settings - Fork 263
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
Added autocompletion for service name #1547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vyasgun: 2 warnings.
In response to this:
Description
Added ValidArgsFunc for autocompletion during
kn service describe
andkn service update
Changes
- Added ValidArgsFunc to
service describe
andservice update
commands./kn service update hello-example<tab> hello-example hello-example-2 hello-example-3 hello-example-4
Reference
Fixes #1373
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Codecov Report
@@ Coverage Diff @@
## main #1547 +/- ##
==========================================
+ Coverage 79.56% 79.57% +0.01%
==========================================
Files 162 163 +1
Lines 8553 8544 -9
==========================================
- Hits 6805 6799 -6
+ Misses 1071 1068 -3
Partials 677 677
Continue to review full report at Codecov.
|
088b3c2
to
c58eb26
Compare
Thanks a ton, @vyasgun ! I hope I can have a look still before the break and lets get it merged then. Great stuff :) |
@rhuss Thanks! It would be great if you could take a look. I can implement for other resources similarly |
c58eb26
to
eea74d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ! (also for adding the extra tests ;-)
Looks good to me on a first view, I have some minor remarks.
|
||
// ResourceNameCompletionFunc will return a function that will autocomplete the name of | ||
// the resource based on the subcommand | ||
func ResourceNameCompletionFunc(p *KnParams) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case when not cobra.ShellCompDirectiveNoFileComp
is returned ? Because then you could remove that return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cobra.ShellCompDirectiveNoFileComp
is being returned in all cases. The function being returned needs to be of this specific signature to be used as a ValidArgsFunction
.
pkg/kn/commands/completion_helper.go
Outdated
command *cobra.Command | ||
args []string | ||
toComplete string | ||
target string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether target
needs to be in an extra field. It's specific only to service
commands and could easily be extracted from the command
when it is already clear that we are dealing with services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think we can remove the field
@@ -43,7 +45,11 @@ func AddNamespaceFlags(flags *pflag.FlagSet, allowAll bool) { | |||
|
|||
// GetNamespace returns namespace from command specified by flag | |||
func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) { | |||
namespace := cmd.Flag("namespace").Value.String() | |||
namespaceFlag := cmd.Flag("namespace") | |||
if namespaceFlag == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding this check !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you :)
The following is the coverage report on the affected files.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dsimansk, vyasgun 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 |
Description
Added ValidArgsFunc for autocompletion during
kn service describe
andkn service update
Changes
service describe
andservice update
commandsReference
Fixes #1373