Merge pull request #30316 from superkooks/main
Fix autocomplete for workspace subcommands
This commit is contained in:
commit
5a9bc76d1a
|
@ -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
|
||||||
|
|
|
@ -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(""),
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(""),
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(""),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue