"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
Add config listproviders, listoptions, jsonconfig for automated config
thierry0575623dffd6
diff --git a/cmd/config/config.go b/cmd/config/config.goindex 3b403146b..f7ad25ed4 100644--- a/cmd/config/config.go+++ b/cmd/config/config.go@@ -26,23 +26,40 @@ Additional functions:* ` + "`rclone config edit`" + ` – same as above* ` + "`rclone config file`" + ` – show path of configuration file in use* ` + "`rclone config show`" + ` – print (decrypted) config file+ * ` + "`rclone config listproviders`" + ` – List, in json format, the protocols supported by sync+ * ` + "`rclone config listoptions type`" + ` – Lists all the options needed to connect to a protocol+ * ` + "`rclone config jsonconfig`name type jsonoptions" + ` – Created a new remote type X with parameters Y`,Run: func(command *cobra.Command, args []string) {- cmd.CheckArgs(0, 1, command, args)+ cmd.CheckArgs(0, 4, command, args)if len(args) == 0 {fs.EditConfig()- return- }-- switch args[0] {- case "edit":- fs.EditConfig()- case "show":- fs.ShowConfig()- case "file":- fs.ShowConfigLocation()- default:- fmt.Fprintf(os.Stderr, "Unknown subcommand %q, %s only supports edit, show and file.\n", args[0], command.Name())+ } else if (len(args) == 1) {+ switch args[0] {+ case "edit":+ fs.EditConfig()+ case "show":+ fs.ShowConfig()+ case "file":+ fs.ShowConfigLocation()+ case "listproviders":+ fs.ListProviders()+ default:+ fmt.Fprintf(os.Stderr, "Unknown subcommand %q, %s only supports edit, show and file.\n", args[0], command.Name())+ }+ } else if (len(args) == 2) {+ if ((args[0] == "listoptions") && (args[1] != "")) {+ fs.ListOptions(args[1])+ } else {+ fmt.Fprintf(os.Stderr, "Unknown subcommand %q %q, %s only supports optionsprovider <type>.\n", args[0], args[1], command.Name())+ }+ } else if (len(args) == 4) {+ if ((args[0] == "jsonconfig") && (args[1] != "") && (args[2] != "") && (args[3]!= "")) {+ fs.JsonConfig(args[1], args[2], args[3])+ } else {+ fmt.Fprintf(os.Stderr, "Unknown subcommand %q %q %q %q, %s only supports jsonconfig <name> <type> <json:options>.\n", args[0], args[1], args[2], args[3], command.Name())+ }}+ return},}diff --git a/fs/config.go b/fs/config.goindex df01ea9d8..fd525b8e7 100644--- a/fs/config.go+++ b/fs/config.go@@ -10,6 +10,7 @@ import ("crypto/rand""crypto/sha256""encoding/base64"+ "encoding/json""fmt""io""io/ioutil"@@ -991,6 +992,58 @@ func ChooseOption(o *Option) string {return ReadLine()}+// JsonConfig Created a new remote type X with parameters Y+func JsonConfig(name string, provider string, jsonstr string) {+ bytes := []byte(jsonstr)++ // Unmarshal string into structs.+ var options []Option+ json.Unmarshal(bytes, &options)++ configData.SetValue(name, "type", provider)+ // Loop over structs and display them.+ for op := range options {+ configData.SetValue(name, options[op].Name, options[op].Value)+ }+ configData.SetValue(name, ConfigAutomatic, "yes")+ RemoteConfig(name)+ ShowRemote(name)+ SaveConfig()+}++// ListOptions Lists all the options needed to connect to a protocol+func ListOptions(provider string) {+ fs := MustFind(provider)+ b, err := json.Marshal(fs.Options)+ if err != nil {+ fmt.Println("error:", err)+ }+ os.Stdout.Write(b)+}++// ListProviders print all providersList, in json format, the protocols supported by sync+func ListProviders() {+ o := &Option{+ Name: "Storage",+ Help: "Type of storage to configure.",+ }+ for _, item := range fsRegistry {+ example := OptionExample{+ Value: item.Name,+ Help: item.Description,+ }+ o.Examples = append(o.Examples, example)+ }+ if len(o.Examples) > 0 {+ o.Examples.Sort()+ b, err := json.Marshal(o.Examples)+ if err != nil {+ fmt.Println("error:", err)+ }+ os.Stdout.Write(b)+ }+}+// fsOption returns an Option describing the possible remotesfunc fsOption() *Option {o := &Option{diff --git a/fs/fs.go b/fs/fs.goindex c336e9b38..b5bb5187d 100644--- a/fs/fs.go+++ b/fs/fs.go@@ -76,6 +76,7 @@ type Option struct {Optional boolIsPassword boolExamples OptionExamples+ Value string}// OptionExamples is a slice of examples