-
Notifications
You must be signed in to change notification settings - Fork 39.1k
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
cmd/get: Remove cmd argument from Run() #114682
Conversation
/hold |
Removes the need to pass cmd as an argument to Run(). This change required reading the --sort-by flag in Complete() in a way similar to other flags. This change allows the cobra.Command not to need to be passed throughout the completion code, which I updated as part of this commit. It also is a step in the direction of the TODO comment requesting the removal of arguments passed to Run() and watch().
8c8fdcb
to
aa7a828
Compare
/retest |
@@ -82,11 +83,11 @@ func ResourceNameCompletionFunc(f cmdutil.Factory, resourceType string) func(*co | |||
// 1- pod names that match the toComplete prefix | |||
// 2- resource types containing pods which match the toComplete prefix | |||
func PodResourceNameCompletionFunc(f cmdutil.Factory) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { | |||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | |||
return func(_ *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.
Sorry if this is dumb but what's the point of this? Is it just because this is possibly being used elsewhere and you just want to throw the first function input away, because it would drastically balloon the PR if you went around and updated the usages everywhere in the code base?
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.
The underscore you mean? It just explicitly indicates that the parameter is unused. If I recall correctly, the function signature is defined by cobra, so it can't be changed, but we are not using the cmd arg.
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.
Oh I see it now, thanks.
@@ -513,14 +511,9 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e | |||
objs[ix] = infos[ix].Object | |||
} | |||
|
|||
sorting, err := cmd.Flags().GetString("sort-by") |
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.
Now we are removing this line because it is already set in Complete
. But we are not executing Complete
function in here
// Do the steps Complete() would have done. |
Maybe completions do not use sort-by flag and this change will not create any problem?
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 don't think allowing users to customize sorting for completions is really necessary. This seems fine to me. If we wanted to add it later we could I guess. Just set the o.SortBy
manually in the completion code.
/lgtm imo. Reminding me that I really need to work on mine for config. |
/lgtm |
LGTM label has been added. Git tree hash: 0cd72da43bd1d52951cd26e13a8e5f491113761d
|
/assign @soltysh |
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.
/lgtm
/hold cancel
/triage accepted |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brianpursley, soltysh 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 |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Removes the need to pass cmd as an argument to Run(). This change required reading the --sort-by flag in Complete() in a way similar to other flags.
This change allows the cobra.Command not to need to be passed throughout the completion code, which I updated as part of this commit.
It also is a step in the direction of the TODO comment requesting the removal of arguments passed to Run() and watch().
Which issue(s) this PR fixes:
Indirectly related to kubernetes/kubectl#1046
Special notes for your reviewer:
The motivation for this is, I want to get to a place where factory can be removed from the completion package. This is a step towards that.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: