chinampa/internal/commands/generate_completions.go

31 lines
843 B
Go
Raw Permalink Normal View History

2022-12-31 05:53:24 +00:00
// SPDX-License-Identifier: Apache-2.0
// 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,
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
},
}