2016-08-05 16:12:27 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ncw/rclone/cmd"
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-10-14 10:50:41 +00:00
|
|
|
cmd.Root.AddCommand(configCommand)
|
|
|
|
configCommand.AddCommand(configEditCommand)
|
|
|
|
configCommand.AddCommand(configFileCommand)
|
|
|
|
configCommand.AddCommand(configShowCommand)
|
|
|
|
configCommand.AddCommand(configDumpCommand)
|
|
|
|
configCommand.AddCommand(configProvidersCommand)
|
|
|
|
configCommand.AddCommand(configCreateCommand)
|
|
|
|
configCommand.AddCommand(configUpdateCommand)
|
|
|
|
configCommand.AddCommand(configDeleteCommand)
|
2016-08-05 16:12:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 10:50:41 +00:00
|
|
|
var configCommand = &cobra.Command{
|
|
|
|
Use: "config",
|
2016-08-05 16:12:27 +00:00
|
|
|
Short: `Enter an interactive configuration session.`,
|
2017-10-14 10:50:41 +00:00
|
|
|
Long: `Enter an interactive configuration session where you can setup new
|
|
|
|
remotes and manage existing ones. You may also set or remove a
|
|
|
|
password to protect your configuration.
|
|
|
|
`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
|
|
|
fs.EditConfig()
|
|
|
|
},
|
|
|
|
}
|
2017-09-19 15:59:19 +00:00
|
|
|
|
2017-10-14 10:50:41 +00:00
|
|
|
var configEditCommand = &cobra.Command{
|
|
|
|
Use: "edit",
|
|
|
|
Short: configCommand.Short,
|
|
|
|
Long: configCommand.Long,
|
|
|
|
Run: configCommand.Run,
|
|
|
|
}
|
2017-09-19 15:59:19 +00:00
|
|
|
|
2017-10-14 10:50:41 +00:00
|
|
|
var configFileCommand = &cobra.Command{
|
|
|
|
Use: "file",
|
|
|
|
Short: `Show path of configuration file in use.`,
|
2016-08-05 16:12:27 +00:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
2017-10-14 10:50:41 +00:00
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
|
|
|
fs.ShowConfigLocation()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configShowCommand = &cobra.Command{
|
|
|
|
Use: "show [<remote>]",
|
|
|
|
Short: `Print (decrypted) config file, or the config for a single remote.`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 1, command, args)
|
2017-09-19 15:59:19 +00:00
|
|
|
if len(args) == 0 {
|
2017-10-14 10:50:41 +00:00
|
|
|
fs.ShowConfig()
|
|
|
|
} else {
|
|
|
|
fs.ShowRemote(args[0])
|
2017-09-19 15:59:19 +00:00
|
|
|
}
|
2017-10-14 10:50:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configDumpCommand = &cobra.Command{
|
|
|
|
Use: "dump",
|
|
|
|
Short: `Dump the config file as JSON.`,
|
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
|
|
|
return fs.ConfigDump()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configProvidersCommand = &cobra.Command{
|
|
|
|
Use: "providers",
|
|
|
|
Short: `List in JSON format all the providers and options.`,
|
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
|
|
|
return fs.JSONListProviders()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configCreateCommand = &cobra.Command{
|
|
|
|
Use: "create <name> <type> [<key> <value>]*",
|
|
|
|
Short: `Create a new remote with name, type and options.`,
|
|
|
|
Long: `
|
|
|
|
Create a new remote of <name> with <type> and options. The options
|
|
|
|
should be passed in in pairs of <key> <value>.
|
|
|
|
|
|
|
|
For example to make a swift remote of name myremote using auto config
|
|
|
|
you would do:
|
|
|
|
|
|
|
|
rclone config create myremote swift env_auth true
|
|
|
|
`,
|
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
|
|
cmd.CheckArgs(2, 256, command, args)
|
|
|
|
return fs.CreateRemote(args[0], args[1], args[2:])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configUpdateCommand = &cobra.Command{
|
|
|
|
Use: "update <name> [<key> <value>]+",
|
|
|
|
Short: `Update options in an existing remote.`,
|
|
|
|
Long: `
|
|
|
|
Update an existing remote's options. The options should be passed in
|
|
|
|
in pairs of <key> <value>.
|
|
|
|
|
|
|
|
For example to update the env_auth field of a remote of name myremote you would do:
|
|
|
|
|
|
|
|
rclone config update myremote swift env_auth true
|
|
|
|
`,
|
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
|
|
cmd.CheckArgs(3, 256, command, args)
|
|
|
|
return fs.UpdateRemote(args[0], args[1:])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var configDeleteCommand = &cobra.Command{
|
|
|
|
Use: "delete <name>",
|
|
|
|
Short: `Delete an existing remote <name>.`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
|
|
fs.DeleteRemote(args[0])
|
2016-08-05 16:12:27 +00:00
|
|
|
},
|
|
|
|
}
|