Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

config: tidy code to use UpdateRemote/CreateRemote instead of editOptions #3455

Nick Craig-Wood77cda6773ca6
diff --git a/fs/config/config.go b/fs/config/config.go
index 7ecbbb424..d02bc67ea 100644
--- a/fs/config/config.go
+++ b/fs/config/config.go
@@ -425,14 +425,15 @@ type UpdateRemoteOpt struct {
State string `json:"state"`
// Result to return - used with Continue
Result string `json:"result"`
+ // If set then edit existing values
+ Edit bool `json:"edit"`
}
-// UpdateRemote adds the keyValues passed in to the remote of name.
-// keyValues should be key, value pairs.
-func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt UpdateRemoteOpt) (out *fs.ConfigOut, err error) {
+func updateRemote(ctx context.Context, name string, keyValues rc.Params, opt UpdateRemoteOpt) (out *fs.ConfigOut, err error) {
if opt.Obscure && opt.NoObscure {
return nil, errors.New("can't use --obscure and --no-obscure together")
}
+
err = fspath.CheckConfigName(name)
if err != nil {
return nil, err
@@ -485,6 +486,9 @@ func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd
m.Set(k, vStr)
}
}
+ if opt.Edit {
+ choices[fs.ConfigEdit] = "true"
+ }
if interactive {
var state = ""
@@ -511,10 +515,17 @@ func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd
return out, nil
}
-// CreateRemote creates a new remote with name, provider and a list of
+// UpdateRemote adds the keyValues passed in to the remote of name.
+// keyValues should be key, value pairs.
+func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt UpdateRemoteOpt) (out *fs.ConfigOut, err error) {
+ opt.Edit = true
+ return updateRemote(ctx, name, keyValues, opt)
+}
+
+// CreateRemote creates a new remote with name, type and a list of
// parameters which are key, value pairs. If update is set then it
// adds the new keys rather than replacing all of them.
-func CreateRemote(ctx context.Context, name string, provider string, keyValues rc.Params, opts UpdateRemoteOpt) (out *fs.ConfigOut, err error) {
+func CreateRemote(ctx context.Context, name string, Type string, keyValues rc.Params, opts UpdateRemoteOpt) (out *fs.ConfigOut, err error) {
err = fspath.CheckConfigName(name)
if err != nil {
return nil, err
@@ -523,7 +534,7 @@ func CreateRemote(ctx context.Context, name string, provider string, keyValues r
// Delete the old config if it exists
LoadedData().DeleteSection(name)
// Set the type
- LoadedData().SetValue(name, "type", provider)
+ LoadedData().SetValue(name, "type", Type)
}
// Set the remaining values
return UpdateRemote(ctx, name, keyValues, opts)
diff --git a/fs/config/ui.go b/fs/config/ui.go
index 2b72f3ba3..9c56ae420 100644
--- a/fs/config/ui.go
+++ b/fs/config/ui.go
@@ -422,17 +422,6 @@ func NewRemoteName() (name string) {
}
}
-// editOptions edits the options. If new is true then it just allows
-// entry and doesn't show any old values.
-func editOptions(ctx context.Context, ri *fs.RegInfo, name string, isNew bool) error {
- fmt.Printf("** See help for %s backend at: https://rclone.org/%s/ **\n\n", ri.Name, ri.FileName())
- m := fs.ConfigMap(ri, name, nil)
- choices := configmap.Simple{
- fs.ConfigEdit: fmt.Sprint(isNew),
- }
- return backendConfig(ctx, name, m, ri, choices, fs.ConfigAll)
-}
-
// NewRemote make a new remote from its name
func NewRemote(ctx context.Context, name string) error {
var (
@@ -453,7 +442,9 @@ func NewRemote(ctx context.Context, name string) error {
}
LoadedData().SetValue(name, "type", newType)
- err = editOptions(ctx, ri, name, true)
+ _, err = CreateRemote(ctx, name, newType, nil, UpdateRemoteOpt{
+ All: true,
+ })
if err != nil {
return err
}
@@ -469,7 +460,9 @@ func EditRemote(ctx context.Context, ri *fs.RegInfo, name string) error {
ShowRemote(name)
fmt.Printf("Edit remote\n")
for {
- err := editOptions(ctx, ri, name, true)
+ _, err := UpdateRemote(ctx, name, nil, UpdateRemoteOpt{
+ All: true,
+ })
if err != nil {
return err
}