config: add rc operations for config

This commit is contained in:
Nick Craig-Wood
2018-11-04 18:23:12 +00:00
parent e600217666
commit e6dd121f52
4 changed files with 414 additions and 34 deletions

View File

@@ -1,8 +1,11 @@
package config
import (
"errors"
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs/config"
"github.com/ncw/rclone/fs/rc"
"github.com/spf13/cobra"
)
@@ -93,7 +96,16 @@ you would do:
`,
RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(2, 256, command, args)
return config.CreateRemote(args[0], args[1], args[2:])
in, err := argsToMap(args[2:])
if err != nil {
return err
}
err = config.CreateRemote(args[0], args[1], in)
if err != nil {
return err
}
config.ShowRemote(args[0])
return nil
},
}
@@ -110,7 +122,16 @@ For example to update the env_auth field of a remote of name myremote you would
`,
RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(3, 256, command, args)
return config.UpdateRemote(args[0], args[1:])
in, err := argsToMap(args[1:])
if err != nil {
return err
}
err = config.UpdateRemote(args[0], in)
if err != nil {
return err
}
config.ShowRemote(args[0])
return nil
},
}
@@ -136,6 +157,29 @@ For example to set password of a remote of name myremote you would do:
`,
RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(3, 256, command, args)
return config.PasswordRemote(args[0], args[1:])
in, err := argsToMap(args[1:])
if err != nil {
return err
}
err = config.PasswordRemote(args[0], in)
if err != nil {
return err
}
config.ShowRemote(args[0])
return nil
},
}
// This takes a list of arguments in key value key value form and
// converts it into a map
func argsToMap(args []string) (out rc.Params, err error) {
if len(args)%2 != 0 {
return nil, errors.New("found key without value")
}
out = rc.Params{}
// Set the config
for i := 0; i < len(args); i += 2 {
out[args[i]] = args[i+1]
}
return out, nil
}