Skip to content

Commit bf2fc6e

Browse files
Merge pull request #276 from dropbox/put-json-output
Add --output=json support to put command
2 parents 3dd5b60 + 8362935 commit bf2fc6e

4 files changed

Lines changed: 698 additions & 64 deletions

File tree

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ $ dbxcli search --output=json report /Reports
145145
$ dbxcli revs --output=json /Reports/old.pdf
146146
$ dbxcli cp --output=json /Reports/old.pdf /Reports/copy.pdf
147147
$ dbxcli mv --output=json /Reports/copy.pdf /Reports/archive/copy.pdf
148+
$ dbxcli put --output=json README.md /README.md
148149
$ dbxcli share-link create --output=json /Reports/old.pdf
149150
$ dbxcli share-link list --output=json /Reports/old.pdf
150151
$ dbxcli mkdir --output=json /new-folder
151152
$ dbxcli rm --output=json /old-file.txt
152153
$ dbxcli restore --output=json /Reports/old.pdf 015f...
153154
```
154155

155-
Structured success output is rolling out command by command. Currently migrated commands are `account`, `du`, `ls`, `search`, `revs`, `cp`, `mv`, `share-link create`, `share-link list`, `share-link info`, `share-link update`, `share-link revoke`, `share-link download`, `mkdir`, `rm`, and `restore`. Commands that have not been migrated return a JSON error whose `error.message` is `structured output is not supported for this command yet` when used with `--output=json`.
156+
Structured success output is rolling out command by command. Currently migrated commands are `account`, `du`, `ls`, `search`, `revs`, `cp`, `mv`, `put`, `share-link create`, `share-link list`, `share-link info`, `share-link update`, `share-link revoke`, `share-link download`, `mkdir`, `rm`, and `restore`. Commands that have not been migrated return a JSON error whose `error.message` is `structured output is not supported for this command yet` when used with `--output=json`.
156157

157158
Command results are written to stdout. Status, progress, warnings, diagnostics, and verbose logs are written to stderr.
158159

@@ -221,6 +222,38 @@ For commands such as `rm`, `input` uses command-specific path and flag fields:
221222
}
222223
```
223224

225+
`put` always returns a `results` array, including single-file and stdin uploads. The top-level `input` describes the command request; each result reports whether a file was `uploaded`, `skipped`, or a directory was `created` or already `existing`:
226+
227+
```json
228+
{
229+
"input": {
230+
"source": "README.md",
231+
"target": "/README.md",
232+
"recursive": false,
233+
"if_exists": "overwrite",
234+
"stdin": false
235+
},
236+
"results": [
237+
{
238+
"status": "uploaded",
239+
"kind": "file",
240+
"input": {
241+
"source": "README.md",
242+
"target": "/README.md"
243+
},
244+
"result": {
245+
"type": "file",
246+
"path_display": "/README.md",
247+
"path_lower": "/readme.md",
248+
"id": "id:...",
249+
"rev": "...",
250+
"size": 123
251+
}
252+
}
253+
]
254+
}
255+
```
256+
224257
Commands that return entry lists, such as `ls`, `search`, and `revs`, return an `input` object and an `entries` array. `ls` input includes the listed path; `search` input includes the query and optional path scope; `revs` input includes the file path:
225258

226259
```json

cmd/json_metadata.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type jsonMetadata struct {
2121
func jsonMetadataFromDropbox(metadata files.IsMetadata) jsonMetadata {
2222
switch m := metadata.(type) {
2323
case *files.FileMetadata:
24+
if m == nil {
25+
return jsonMetadata{Type: "unknown"}
26+
}
2427
size := m.Size
2528
return jsonMetadata{
2629
Type: "file",
@@ -33,13 +36,19 @@ func jsonMetadataFromDropbox(metadata files.IsMetadata) jsonMetadata {
3336
ClientModified: jsonTime(m.ClientModified),
3437
}
3538
case *files.FolderMetadata:
39+
if m == nil {
40+
return jsonMetadata{Type: "unknown"}
41+
}
3642
return jsonMetadata{
3743
Type: "folder",
3844
PathDisplay: m.PathDisplay,
3945
PathLower: m.PathLower,
4046
ID: m.Id,
4147
}
4248
case *files.DeletedMetadata:
49+
if m == nil {
50+
return jsonMetadata{Type: "unknown"}
51+
}
4352
return jsonMetadata{
4453
Type: "deleted",
4554
PathDisplay: m.PathDisplay,

0 commit comments

Comments
 (0)