From 635d1e10ae8d04f6014a8d025c723cfe73b3fc9f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 11 May 2021 13:36:34 +0100 Subject: [PATCH] config create: add --state and --result parameters #3455 --- cmd/config/config.go | 6 ++++-- fs/config/config.go | 19 +++++++------------ fs/config/rc.go | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/config/config.go b/cmd/config/config.go index 1de6a0a31..e7d9359cb 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -159,12 +159,12 @@ This will look something like (some irrelevant detail removed): The format of |Option| is the same as returned by |rclone config providers|. The question should be asked to the user and returned to -rclone as a string parameter along with the state parameter. +rclone as the |--result| option along with the |--state| parameter. If |Error| is set then it should be shown to the user at the same time as the question. - rclone config update name --continue state "*oauth-islocal,teamdrive,," result "true" + rclone config update name --continue --state "*oauth-islocal,teamdrive,," --result "true" Note that when using |--continue| all passwords should be passed in the clear (not obscured). Any default config values should be passed @@ -235,6 +235,8 @@ func init() { flags.BoolVarP(cmdFlags, &updateRemoteOpt.NonInteractive, "non-interactive", "", false, "Don't interact with user and return questions.") flags.BoolVarP(cmdFlags, &updateRemoteOpt.Continue, "continue", "", false, "Continue the configuration process with an answer.") flags.BoolVarP(cmdFlags, &updateRemoteOpt.All, "all", "", false, "Ask the full set of config questions.") + flags.StringVarP(cmdFlags, &updateRemoteOpt.State, "state", "", "", "State - use with --continue.") + flags.StringVarP(cmdFlags, &updateRemoteOpt.Result, "result", "", "", "Result - use with --continue.") } } diff --git a/fs/config/config.go b/fs/config/config.go index 081c154fc..7ecbbb424 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -421,6 +421,10 @@ type UpdateRemoteOpt struct { Continue bool `json:"continue"` // If set then ask all the questions, not just the post config questions All bool `json:"all"` + // State to restart with - used with Continue + State string `json:"state"` + // Result to return - used with Continue + Result string `json:"result"` } // UpdateRemote adds the keyValues passed in to the remote of name. @@ -490,18 +494,9 @@ func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt Upd err = backendConfig(ctx, name, m, ri, choices, state) } else { // Start the config state machine - in := fs.ConfigIn{} - if opt.Continue { - if state, ok := keyValues["state"]; ok { - in.State = fmt.Sprint(state) - } else { - return nil, errors.New("UpdateRemote: need state parameter with --continue") - } - if result, ok := keyValues["result"]; ok { - in.Result = fmt.Sprint(result) - } else { - return nil, errors.New("UpdateRemote: need result parameter with --continue") - } + in := fs.ConfigIn{ + State: opt.State, + Result: opt.Result, } if in.State == "" && opt.All { in.State = fs.ConfigAll diff --git a/fs/config/rc.go b/fs/config/rc.go index fe8dacec9..59dbb9170 100644 --- a/fs/config/rc.go +++ b/fs/config/rc.go @@ -119,6 +119,8 @@ func init() { - nonInteractive - don't interact with a user, return questions - continue - continue the config process with an answer - all - ask all the config questions not just the post config ones + - state - state to restart with - used with continue + - result - result to restart with - used with continue ` } rc.Add(rc.Call{