Skip to content

Commit

Permalink
lxd: Enable cobra's completion support
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
(cherry picked from commit c0200b455a1468685d762649120ce7e2bb25adc9)
Signed-off-by: Kadin Sayani <[email protected]>
License: Apache-2.0
  • Loading branch information
stgraber authored and kadinsayani committed Sep 4, 2024
1 parent f969631 commit 64cdeb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lxc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ All of LXD's features can be driven through the various commands below.
For help with any of those, simply call them with --help.`))
app.SilenceUsage = true
app.SilenceErrors = true
app.CompletionOptions = cobra.CompletionOptions{DisableDefaultCmd: true}
app.CompletionOptions = cobra.CompletionOptions{HiddenDefaultCmd: true}

// Global flags
globalCmd := cmdGlobal{cmd: app, asker: cli.NewAsker(bufio.NewReader(os.Stdin), nil)}
Expand Down Expand Up @@ -278,9 +278,14 @@ For help with any of those, simply call them with --help.`))
if globalCmd.flagHelpAll {
// Show all commands
for _, cmd := range app.Commands() {
if cmd.Name() == "completion" {
continue
}

cmd.Hidden = false
}
}

if globalCmd.flagSubCmds {
app.SetUsageTemplate(usageTemplateSubCmds())
}
Expand Down
9 changes: 9 additions & 0 deletions lxc/manpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func (c *cmdManpage) run(cmd *cobra.Command, args []string) error {
return err
}

// If asked to do all commands, mark them all visible.
for _, c := range c.global.cmd.Commands() {
if c.Name() == "completion" {
continue
}

c.Hidden = false
}

// Generate the documentation.
switch c.flagFormat {
case "man":
Expand Down

0 comments on commit 64cdeb3

Please sign in to comment.