"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
config: add reconnect, userinfo and disconnect subcommands.
Nick Craig-Wooda808e98fe1d1
diff --git a/cmd/config/config.go b/cmd/config/config.goindex 64180aa76..2e650e9ea 100644--- a/cmd/config/config.go+++ b/cmd/config/config.go@@ -1,9 +1,15 @@package configimport (- "errors"+ "context"+ "encoding/json"+ "fmt"+ "os"+ "sort"+ "github.com/pkg/errors""github.com/rclone/rclone/cmd"+ "github.com/rclone/rclone/fs""github.com/rclone/rclone/fs/config""github.com/rclone/rclone/fs/rc""github.com/spf13/cobra"@@ -20,6 +26,9 @@ func init() {configCommand.AddCommand(configUpdateCommand)configCommand.AddCommand(configDeleteCommand)configCommand.AddCommand(configPasswordCommand)+ configCommand.AddCommand(configReconnectCommand)+ configCommand.AddCommand(configDisconnectCommand)+ configCommand.AddCommand(configUserInfoCommand)}var configCommand = &cobra.Command{@@ -207,3 +216,99 @@ func argsToMap(args []string) (out rc.Params, err error) {}return out, nil}++var configReconnectCommand = &cobra.Command{+ Use: "reconnect remote:",+ Short: `Re-authenticates user with remote.`,+ Long: `+This reconnects remote: passed in to the cloud storage system.++To disconnect the remote use "rclone config disconnect".++This normally means going through the interactive oauth flow again.+`,+ RunE: func(command *cobra.Command, args []string) error {+ cmd.CheckArgs(1, 1, command, args)+ fsInfo, configName, _, config, err := fs.ConfigFs(args[0])+ if err != nil {+ return err+ }+ if fsInfo.Config == nil {+ return errors.Errorf("%s: doesn't support Reconnect", configName)+ }+ fsInfo.Config(configName, config)+ return nil+ },+}++var configDisconnectCommand = &cobra.Command{+ Use: "disconnect remote:",+ Short: `Disconnects user from remote`,+ Long: `+This disconnects the remote: passed in to the cloud storage system.++This normally means revoking the oauth token.++To reconnect use "rclone config reconnect".+`,+ RunE: func(command *cobra.Command, args []string) error {+ cmd.CheckArgs(1, 1, command, args)+ f := cmd.NewFsSrc(args)+ doDisconnect := f.Features().Disconnect+ if doDisconnect == nil {+ return errors.Errorf("%v doesn't support Disconnect", f)+ }+ err := doDisconnect(context.Background())+ if err != nil {+ return errors.Wrap(err, "Disconnect call failed")+ }+ return nil+ },+}++var (+ jsonOutput bool+)++func init() {+ configUserInfoCommand.Flags().BoolVar(&jsonOutput, "json", false, "Format output as JSON")+}++var configUserInfoCommand = &cobra.Command{+ Use: "userinfo remote:",+ Short: `Prints info about logged in user of remote.`,+ Long: `+This prints the details of the person logged in to the cloud storage+system.+`,+ RunE: func(command *cobra.Command, args []string) error {+ cmd.CheckArgs(1, 1, command, args)+ f := cmd.NewFsSrc(args)+ doUserInfo := f.Features().UserInfo+ if doUserInfo == nil {+ return errors.Errorf("%v doesn't support UserInfo", f)+ }+ u, err := doUserInfo(context.Background())+ if err != nil {+ return errors.Wrap(err, "UserInfo call failed")+ }+ if jsonOutput {+ out := json.NewEncoder(os.Stdout)+ out.SetIndent("", "\t")+ return out.Encode(u)+ }+ var keys []string+ var maxKeyLen int+ for key := range u {+ keys = append(keys, key)+ if len(key) > maxKeyLen {+ maxKeyLen = len(key)+ }+ }+ sort.Strings(keys)+ for _, key := range keys {+ fmt.Printf("%*s: %s\n", maxKeyLen, key, u[key])+ }+ return nil+ },+}