mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
config: tidy code to use UpdateRemote/CreateRemote instead of editOptions #3455
This commit is contained in:
parent
dbc5167281
commit
77cda6773c
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user