Merge pull request #30316 from superkooks/main

Fix autocomplete for workspace subcommands
This commit is contained in:
Alisdair McDiarmid 2022-01-21 12:01:41 -05:00 committed by GitHub
commit 5a9bc76d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 8 deletions

View File

@ -19,11 +19,7 @@ var completePredictModuleSource = complete.PredictAnything
type completePredictSequence []complete.Predictor type completePredictSequence []complete.Predictor
func (s completePredictSequence) Predict(a complete.Args) []string { func (s completePredictSequence) Predict(a complete.Args) []string {
// Only one level of command is stripped off the prefix of a.Completed // Nested subcommands do not require any placeholder entry for their subcommand name.
// here, so nested subcommands like "workspace new" will need to provide
// dummy entries (e.g. complete.PredictNothing) as placeholders for
// all but the first subcommand. For example, "workspace new" needs
// one placeholder for the argument "new".
idx := len(a.Completed) idx := len(a.Completed)
if idx >= len(s) { if idx >= len(s) {
return nil return nil

View File

@ -190,7 +190,6 @@ func (c *WorkspaceDeleteCommand) Run(args []string) int {
func (c *WorkspaceDeleteCommand) AutocompleteArgs() complete.Predictor { func (c *WorkspaceDeleteCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{ return completePredictSequence{
complete.PredictNothing, // the "select" subcommand itself (already matched)
c.completePredictWorkspaceName(), c.completePredictWorkspaceName(),
complete.PredictDirs(""), complete.PredictDirs(""),
} }

View File

@ -167,7 +167,6 @@ func (c *WorkspaceNewCommand) Run(args []string) int {
func (c *WorkspaceNewCommand) AutocompleteArgs() complete.Predictor { func (c *WorkspaceNewCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{ return completePredictSequence{
complete.PredictNothing, // the "new" subcommand itself (already matched)
complete.PredictAnything, complete.PredictAnything,
complete.PredictDirs(""), complete.PredictDirs(""),
} }

View File

@ -117,7 +117,6 @@ func (c *WorkspaceSelectCommand) Run(args []string) int {
func (c *WorkspaceSelectCommand) AutocompleteArgs() complete.Predictor { func (c *WorkspaceSelectCommand) AutocompleteArgs() complete.Predictor {
return completePredictSequence{ return completePredictSequence{
complete.PredictNothing, // the "select" subcommand itself (already matched)
c.completePredictWorkspaceName(), c.completePredictWorkspaceName(),
complete.PredictDirs(""), complete.PredictDirs(""),
} }