-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[LocalCLI] add completion for --class
and --editor
flags
#19019
Changes from 6 commits
1eb2534
e52e933
bd7394f
bead6f2
eaeac93
f2fb018
07ef7b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,10 +143,53 @@ var workspaceCreateOpts struct { | |
Editor string | ||
} | ||
|
||
func classCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mustard-mh could we decouple this from here and move into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @filiptronicek completion (api call + simple fmt.Sprintf) will only be used in cmd, if we move them to We can call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could follow the approach of I think like this it's also alright. Leaving it up to ya |
||
ctx := cmd.Context() | ||
gitpod, err := getGitpodClient(ctx) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
resp, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{})) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
items := resp.Msg.GetResult() | ||
completionStr := []string{} | ||
for _, cls := range items { | ||
defaultDesc := "" | ||
if cls.IsDefault { | ||
defaultDesc = "(default)" | ||
} | ||
completionStr = append(completionStr, fmt.Sprintf("%s\t%s%s - %s", cls.Id, cls.DisplayName, defaultDesc, cls.Description)) | ||
} | ||
return completionStr, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
func editorCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
ctx := cmd.Context() | ||
gitpod, err := getGitpodClient(ctx) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
resp, err := gitpod.Editors.ListEditorOptions(ctx, connect.NewRequest(&v1.ListEditorOptionsRequest{})) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
items := resp.Msg.GetResult() | ||
completionStr := []string{} | ||
for _, editor := range items { | ||
completionStr = append(completionStr, fmt.Sprintf("%s\t%s", editor.Id, editor.Title)) | ||
} | ||
return completionStr, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
func init() { | ||
workspaceCmd.AddCommand(workspaceCreateCmd) | ||
addWorkspaceStartOptions(workspaceCreateCmd, &workspaceCreateOpts.StartOpts) | ||
|
||
workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.WorkspaceClass, "class", "", "the workspace class") | ||
workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.Editor, "editor", "code", "the editor to use") | ||
|
||
_ = workspaceCreateCmd.RegisterFlagCompletionFunc("class", classCompletionFunc) | ||
_ = workspaceCreateCmd.RegisterFlagCompletionFunc("editor", editorCompletionFunc) | ||
filiptronicek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Could we do this automatically in the
.gitpod.yml
file for the initial install? Would maybe help with testing.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.
We could add this to the README as well
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.
Yep, will do it 👍
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.
@filiptronicek Updated README.md feel free to update it again XD