From 0b8802382e47ef2cd29e56927fd71decb43a5c1a Mon Sep 17 00:00:00 2001 From: montag451 Date: Sat, 16 Nov 2024 14:51:20 +0100 Subject: [PATCH] incus: Add aliases completion Signed-off-by: montag451 --- cmd/incus/main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/incus/main.go b/cmd/incus/main.go index d64a467589..17b72ecd67 100644 --- a/cmd/incus/main.go +++ b/cmd/incus/main.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" - "github.com/lxc/incus/v6/client" + incus "github.com/lxc/incus/v6/client" cli "github.com/lxc/incus/v6/internal/cmd" "github.com/lxc/incus/v6/internal/i18n" internalUtil "github.com/lxc/incus/v6/internal/util" @@ -70,6 +70,23 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e ` } +func aliases() []string { + c, err := config.LoadConfig("") + if err != nil { + return nil + } + + aliases := make([]string, 0, len(defaultAliases)+len(c.Aliases)) + for alias := range defaultAliases { + aliases = append(aliases, alias) + } + for alias := range c.Aliases { + aliases = append(aliases, alias) + } + + return aliases +} + func main() { // Process aliases err := execIfAliases() @@ -92,6 +109,7 @@ Custom commands can be defined through aliases, use "incus alias" to control tho app.SilenceUsage = true app.SilenceErrors = true app.CompletionOptions = cobra.CompletionOptions{HiddenDefaultCmd: true} + app.ValidArgs = aliases() // Global flags globalCmd := cmdGlobal{cmd: app, asker: ask.NewAsker(bufio.NewReader(os.Stdin))}