"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
backend: add --json flag to always output JSON
Nick Craig-Wood995cd0dc32ff
diff --git a/cmd/backend/backend.go b/cmd/backend/backend.goindex 3e8983bff..2d32ff447 100644--- a/cmd/backend/backend.go+++ b/cmd/backend/backend.go@@ -18,12 +18,14 @@ import (var (options []string+ useJSON bool)func init() {cmd.Root.AddCommand(commandDefinition)cmdFlags := commandDefinition.Flags()flags.StringArrayVarP(cmdFlags, &options, "option", "o", options, "Option in the form name=value or name.")+ flags.BoolVarP(cmdFlags, &useJSON, "json", "", useJSON, "Always output in JSON format.")}var commandDefinition = &cobra.Command{@@ -97,15 +99,23 @@ Note to run these commands on a running backend then see}// Output the result- switch x := out.(type) {- case nil:- case string:- fmt.Println(out)- case []string:- for _, line := range x {- fmt.Println(line)+ writeJSON := false+ if useJSON {+ writeJSON = true+ } else {+ switch x := out.(type) {+ case nil:+ case string:+ fmt.Println(out)+ case []string:+ for _, line := range x {+ fmt.Println(line)+ }+ default:+ writeJSON = true}- default:+ }+ if writeJSON {// Write indented JSON to the outputenc := json.NewEncoder(os.Stdout)enc.SetIndent("", "\t")