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

Added autocompletion for service name #1547

Merged
merged 5 commits into from
Jan 4, 2022

Conversation

vyasgun
Copy link
Contributor

@vyasgun vyasgun commented Dec 14, 2021

Description

Added ValidArgsFunc for autocompletion during kn service describe and kn service update

Changes

  • Added ValidArgsFunc to service describe and service update commands
./kn service update hello-example<tab>
hello-example    hello-example-2  hello-example-3  hello-example-4

Reference

Fixes #1373

Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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 and kn service update

Changes

  • Added ValidArgsFunc to service describe and service 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.

pkg/kn/commands/completion_helper.go Show resolved Hide resolved
pkg/kn/commands/completion_helper.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 14, 2021
@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #1547 (5feffed) into main (972eec2) will increase coverage by 0.01%.
The diff coverage is 93.65%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
pkg/kn/commands/service/delete.go 80.32% <ø> (ø)
pkg/kn/commands/completion_helper.go 92.15% <92.15%> (ø)
pkg/kn/commands/namespaced.go 92.50% <100.00%> (+0.60%) ⬆️
pkg/kn/commands/service/describe.go 73.62% <100.00%> (+0.14%) ⬆️
pkg/kn/commands/service/update.go 81.69% <100.00%> (+0.26%) ⬆️
cmd/kn/main.go 66.66% <0.00%> (-20.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 972eec2...5feffed. Read the comment docs.

@vyasgun vyasgun force-pushed the pr/completion branch 2 times, most recently from 088b3c2 to c58eb26 Compare December 21, 2021 09:27
@rhuss
Copy link
Contributor

rhuss commented Dec 21, 2021

Thanks a ton, @vyasgun ! I hope I can have a look still before the break and lets get it merged then. Great stuff :)

@vyasgun
Copy link
Contributor Author

vyasgun commented Dec 21, 2021

@rhuss Thanks! It would be great if you could take a look. I can implement for other resources similarly

Copy link
Contributor

@rhuss rhuss left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@vyasgun vyasgun Dec 22, 2021

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.

command *cobra.Command
args []string
toComplete string
target string
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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 !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you :)

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/completion_helper.go Do not exist 96.0%
pkg/kn/commands/namespaced.go 96.3% 96.7% 0.4

Copy link
Contributor

@dsimansk dsimansk left a comment

Choose a reason for hiding this comment

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

Thanks!

/approve
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 4, 2022
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 4, 2022
@knative-prow-robot knative-prow-robot merged commit 6314298 into knative:main Jan 4, 2022
@rhuss rhuss mentioned this pull request Jan 5, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Context sensitive Bash completion
5 participants