Skip to content

Commit

Permalink
incus: Add aliases completion
Browse files Browse the repository at this point in the history
Signed-off-by: montag451 <montag451@laposte.net>
  • Loading branch information
montag451 committed Nov 16, 2024
1 parent 41e49d4 commit 0b88023
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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))}
Expand Down

0 comments on commit 0b88023

Please sign in to comment.