Add genautocomplete command to make bash completion script.

This commit is contained in:
Nick Craig-Wood 2016-08-03 20:41:08 +01:00
parent 38adb35abe
commit 2df261e42b

View File

@ -82,7 +82,8 @@ func init() {
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
configCmd, authorizeCmd, cleanupCmd, memtestCmd, versionCmd)
genautocompleteCmd, configCmd, authorizeCmd,
cleanupCmd, memtestCmd, versionCmd)
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
cobra.OnInitialize(initConfig)
}
@ -479,6 +480,38 @@ var configCmd = &cobra.Command{
},
}
var genautocompleteCmd = &cobra.Command{
Use: "genautocomplete [output_file]",
Short: `Output bash completion script for rclone.`,
Long: `
Generates a bash shell autocompletion script for rclone.
This writes to /etc/bash_completion.d/rclone by default so will
probably need to be run with sudo or as root, eg
sudo rclone genautocomplete
Logout and login again to use the autocompletion scripts, or source
them directly
. /etc/bash_completion
If you supply a command line argument the script will be written
there.
`,
Run: func(cmd *cobra.Command, args []string) {
checkArgs(0, 1, cmd, args)
out := "/etc/bash_completion.d/rclone"
if len(args) > 0 {
out = args[0]
}
err := rootCmd.GenBashCompletionFile(out)
if err != nil {
log.Fatal(err)
}
},
}
var authorizeCmd = &cobra.Command{
Use: "authorize",
Short: `Remote authorization.`,