-
Notifications
You must be signed in to change notification settings - Fork 603
[Feat][kubectl-plugin] Add dynamic shell completion for kubectl ray session #2390
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
[Feat][kubectl-plugin] Add dynamic shell completion for kubectl ray session #2390
Conversation
…ession Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
The demo video looks good! Is it only for |
@kevin85421 Currently only session command. |
@MortalHappiness the autocomplete looks awesome, can't wait to try it!
@chiayi can we look into implementing similar autocompletion for |
} | ||
|
||
// RayJobCompletionFunc Returns a completion function that completes RayJob resource names. | ||
func RayJobCompletionFunc(f cmdutil.Factory) func(*cobra.Command, []string, 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 RayJobCompletionFunc
and RayServiceCompletionFunc
still needed? It looks like RayClusterResourceNameCompletionFunc
handles resource type already
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.
These 3 functions RayClusterCompletionFunc
, RayJobCompletionFunc
, and RayServiceCompletionFunc
are not used in this PR. But I think they may be useful for implementing autocompletion for other commands. Let me introduce the differences:
RayClusterResourceNameCompletionFunc
:
- If
toComplete
does not have slash, complete it from either RayCluster names or resource types (raycluster/
,rayjob/
,rayservice/
) - If
toComplete
starts with resource types and slash, complete it with the corresponding resource name (e.g.rayjob/sample-rayjob
) - Examples:
r<Tab>
->raycluster-1
,raycluster-2
,raycluster/
,rayjob/
,rayservice/
m<Tab>
->my-raycluster-1
,my-raycluster-2
rayjob/<Tab>
->rayjob/rayjob-1
,rayjob/rayjob-2
RayClusterCompletionFunc
, RayJobCompletionFunc
, RayServiceCompletionFunc
:
- These functions only complete the resource name of the corresponding resource. For example, for
RayJobCompletionFunc
, the completion result will not includerayjob/
, only the name of RayJobs are presented to the users. - So these function can be used by other commands that don't need resource type completion. For example,
kubectl ray logs
can useRayClusterCompletionFunc
. cc @chiayi - Examples (
RayClusterCompletionFunc
):r<Tab>
->raycluster-1
,raycluster-2
Note that the r<Tab>
results are different for RayClusterResourceNameCompletionFunc
and RayClusterCompletionFunc
.
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.
okay that makes sense to me, thanks for clarifying
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
Why are these changes needed?
Implement dynamic shell completion for
kubectl ray session
command.Note: I haven't found a proper way to mock the cmd Factory to get custom resources for testing.
Screencast:
2024-09-18.17-35-09.mp4
Related issue number
N/A
Checks