mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
config: add config/setpath for setting config path via rc/librclone
This commit is contained in:
parent
7edb4c0162
commit
67fc227684
@ -217,3 +217,27 @@ func rcDelete(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
DeleteRemote(name)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
rc.Add(rc.Call{
|
||||
Path: "config/setpath",
|
||||
Fn: rcSetPath,
|
||||
Title: "Set the path of the config file",
|
||||
AuthRequired: true,
|
||||
Help: `
|
||||
Parameters:
|
||||
|
||||
- path - path to the config file to use
|
||||
`,
|
||||
})
|
||||
}
|
||||
|
||||
// Set the config file path
|
||||
func rcSetPath(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||
path, err := in.GetString("path")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = SetConfigPath(path)
|
||||
return nil, err
|
||||
}
|
||||
|
@ -153,3 +153,21 @@ func TestRcProviders(t *testing.T) {
|
||||
}
|
||||
assert.True(t, foundLocal, "didn't find local provider")
|
||||
}
|
||||
|
||||
func TestRcSetPath(t *testing.T) {
|
||||
oldPath := config.GetConfigPath()
|
||||
newPath := oldPath + ".newPath"
|
||||
call := rc.Calls.Get("config/setpath")
|
||||
assert.NotNil(t, call)
|
||||
in := rc.Params{
|
||||
"path": newPath,
|
||||
}
|
||||
_, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newPath, config.GetConfigPath())
|
||||
|
||||
in["path"] = oldPath
|
||||
_, err = call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldPath, config.GetConfigPath())
|
||||
}
|
||||
|
@ -113,6 +113,9 @@ int main(int argc, char** argv) {
|
||||
/* testCopyFile(); */
|
||||
/* testListRemotes(); */
|
||||
|
||||
/* testRPC("config/setpath", "{\"path\":\"/tmp/rclone.conf\"}"); */
|
||||
/* testRPC("config/listremotes", "{}"); */
|
||||
|
||||
RcloneFinalize();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user