2022-12-31 05:53:24 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2023-03-21 04:18:09 +00:00
|
|
|
// Copyright © 2022 Roberto Hidalgo <chinampa@un.rob.mx>
|
2022-12-31 05:53:24 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var GenerateCompletions = &cobra.Command{
|
|
|
|
Use: "__generate_completions [bash|zsh|fish]",
|
|
|
|
Short: "Outputs a shell-specific script for autocompletions that can be piped into a file",
|
|
|
|
Hidden: true,
|
|
|
|
DisableAutoGenTag: true,
|
|
|
|
SilenceUsage: true,
|
2023-03-21 04:18:09 +00:00
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
ValidArgs: []string{"bash", "fish", "zsh"},
|
2022-12-31 05:53:24 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|
|
|
switch args[0] {
|
|
|
|
case "bash":
|
|
|
|
err = cmd.Root().GenBashCompletionV2(os.Stdout, true)
|
|
|
|
case "zsh":
|
|
|
|
err = cmd.Root().GenZshCompletion(os.Stdout)
|
|
|
|
case "fish":
|
|
|
|
err = cmd.Root().GenFishCompletion(os.Stdout, true)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
},
|
|
|
|
}
|