From 6c31c665625bb58ab0bc4977c7e310b021067ea2 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 4 Sep 2018 17:27:20 -0700 Subject: [PATCH] hidden bashcomp command --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index c520ce3..575ac86 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/zrepl/zrepl/daemon" "log" "os" + "fmt" ) var rootCmd = &cobra.Command{ @@ -69,6 +70,24 @@ var stdinserverCmd = &cobra.Command{ }, } + +var bashcompCmd = &cobra.Command{ + Use: "bashcomp path/to/out/file", + Short: "generate bash completions", + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 1 { + fmt.Fprintf(os.Stderr, "specify exactly one positional agument\n") + cmd.Usage() + os.Exit(1) + } + if err := rootCmd.GenBashCompletionFile(args[0]); err != nil { + fmt.Fprintf(os.Stderr, "error generating bash completion: %s", err) + os.Exit(1) + } + }, + Hidden: true, +} + var rootArgs struct { configFile string } @@ -80,6 +99,7 @@ func init() { rootCmd.AddCommand(wakeupCmd) rootCmd.AddCommand(statusCmd) rootCmd.AddCommand(stdinserverCmd) + rootCmd.AddCommand(bashcompCmd) } func main() {