genautocomplete: add support to output to stdout

This commit is contained in:
Ingo
2020-10-10 22:16:21 +01:00
committed by Nick Craig-Wood
parent ffdd0719e7
commit 5164c3d2d0
8 changed files with 101 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package genautocomplete
import (
"log"
"os"
"github.com/rclone/rclone/cmd"
"github.com/spf13/cobra"
@@ -29,11 +30,20 @@ them directly
If you supply a command line argument the script will be written
there.
If output_file is "-", then the output will be written to stdout.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(0, 1, command, args)
out := "/etc/bash_completion.d/rclone"
if len(args) > 0 {
if args[0] == "-" {
err := cmd.Root.GenBashCompletion(os.Stdout)
if err != nil {
log.Fatal(err)
}
return
}
out = args[0]
}
err := cmd.Root.GenBashCompletionFile(out)