mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
rc: allow JSON parameters to simplify command line usage
If the parameter being passed is an object then it can be passed as a
JSON string rather than using the `--json` flag which simplifies the
command line.
rclone rc operations/list fs=/tmp remote=test opt='{"showHash": true}'
Rather than
rclone rc operations/list --json '{"fs": "/tmp", "remote": "test", "opt": {"showHash": true}}'
This commit is contained in:
@@ -219,6 +219,13 @@ func (p Params) GetStruct(key string, out interface{}) error {
|
||||
}
|
||||
err = Reshape(out, value)
|
||||
if err != nil {
|
||||
if valueStr, ok := value.(string); ok {
|
||||
// try to unmarshal as JSON if string
|
||||
err = json.Unmarshal([]byte(valueStr), out)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrParamInvalid{errors.Wrapf(err, "key %q", key)}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user