Skip to content

Commit 6ea6381

Browse files
Merge pull request #302 from dropbox/v3/stable-exit-codes
Bump module path to v3 and add stable exit codes
2 parents 45fcded + e956121 commit 6ea6381

25 files changed

Lines changed: 355 additions & 33 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# `dbxcli`: Dropbox from the command line
22

33
[![CI](https://github.com/dropbox/dbxcli/actions/workflows/ci.yml/badge.svg)](https://github.com/dropbox/dbxcli/actions/workflows/ci.yml)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/dropbox/dbxcli)](https://goreportcard.com/report/github.com/dropbox/dbxcli)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/dropbox/dbxcli/v3)](https://goreportcard.com/report/github.com/dropbox/dbxcli/v3)
55

66
`dbxcli` is a scriptable Dropbox CLI for files, shared links, teams, and
77
automation workflows. It is built for humans at the terminal, scripts, CI jobs,
@@ -126,7 +126,7 @@ Release assets include:
126126
### Build from source
127127

128128
```sh
129-
go install github.com/dropbox/dbxcli@latest
129+
go install github.com/dropbox/dbxcli/v3@latest
130130
```
131131

132132
Or build from a clone:

cmd/cp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"github.com/dropbox/dbxcli/internal/output"
21+
"github.com/dropbox/dbxcli/v3/internal/output"
2222
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
2323
"github.com/spf13/cobra"
2424
)

cmd/cp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/dropbox/dbxcli/internal/output"
14+
"github.com/dropbox/dbxcli/v3/internal/output"
1515
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
1616
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
1717
"github.com/spf13/cobra"

cmd/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/dropbox/dbxcli/internal/output"
27+
"github.com/dropbox/dbxcli/v3/internal/output"
2828
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
2929
"github.com/dustin/go-humanize"
3030
"github.com/mitchellh/ioprogress"

cmd/help_json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"sort"
66
"strings"
77

8-
"github.com/dropbox/dbxcli/internal/output"
8+
"github.com/dropbox/dbxcli/v3/internal/output"
99
"github.com/spf13/cobra"
1010
"github.com/spf13/pflag"
1111
)

cmd/json_contract_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/dropbox/dbxcli/internal/output"
13+
"github.com/dropbox/dbxcli/v3/internal/output"
1414
"github.com/spf13/cobra"
1515
)
1616

@@ -519,6 +519,7 @@ func expectedJSONErrorCodes() []string {
519519
jsonErrorCodeEnvTokenStillActive,
520520
jsonErrorCodeInvalidArguments,
521521
jsonErrorCodeNotFound,
522+
jsonErrorCodePartialTransfer,
522523
jsonErrorCodePathConflict,
523524
jsonErrorCodePermissionDenied,
524525
jsonErrorCodeRateLimited,

cmd/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"os"
2020
"sort"
2121

22-
"github.com/dropbox/dbxcli/internal/output"
22+
"github.com/dropbox/dbxcli/v3/internal/output"
2323
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
2424
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/auth"
2525
"github.com/spf13/cobra"

cmd/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"strings"
2222
"text/tabwriter"
2323

24-
"github.com/dropbox/dbxcli/internal/output"
24+
"github.com/dropbox/dbxcli/v3/internal/output"
2525
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
2626
"github.com/dustin/go-humanize"
2727
"github.com/spf13/cobra"

cmd/mv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"github.com/dropbox/dbxcli/internal/output"
21+
"github.com/dropbox/dbxcli/v3/internal/output"
2222
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
2323
"github.com/spf13/cobra"
2424
)

cmd/output.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"reflect"
77
"strings"
88

9-
"github.com/dropbox/dbxcli/internal/output"
9+
"github.com/dropbox/dbxcli/v3/internal/output"
1010
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
1111
dropboxauth "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/auth"
1212
"github.com/spf13/cobra"
@@ -25,6 +25,7 @@ const (
2525
jsonErrorCodeEnvTokenStillActive = "env_token_still_active"
2626
jsonErrorCodeInvalidArguments = "invalid_arguments"
2727
jsonErrorCodeNotFound = "not_found"
28+
jsonErrorCodePartialTransfer = "partial_transfer"
2829
jsonErrorCodePathConflict = "path_conflict"
2930
jsonErrorCodePermissionDenied = "permission_denied"
3031
jsonErrorCodeRateLimited = "rate_limited"
@@ -33,6 +34,18 @@ const (
3334
jsonErrorCodeUnknownFlag = "unknown_flag"
3435
)
3536

37+
const (
38+
exitCodeSuccess = 0
39+
exitCodeGenericError = 1
40+
exitCodeAuthFailure = 2
41+
exitCodePermissionDenied = 3
42+
exitCodeNotFound = 4
43+
exitCodeConflict = 5
44+
exitCodeRateLimited = 6
45+
exitCodeValidationError = 7
46+
exitCodePartialTransfer = 8
47+
)
48+
3649
type jsonCodedError interface {
3750
error
3851
JSONErrorCode() string
@@ -202,7 +215,11 @@ func parseOutputFormat(value string) (output.Format, error) {
202215
case output.FormatJSON:
203216
return output.FormatJSON, nil
204217
default:
205-
return "", fmt.Errorf("unsupported output format %q: use text or json", value)
218+
return "", invalidArgumentsErrorfWithDetails(
219+
"unsupported output format %q: use text or json",
220+
flagValueErrorDetails(outputFlag, value),
221+
value,
222+
)
206223
}
207224
}
208225

@@ -276,6 +293,38 @@ func renderCommandErrorWithJSON(cmd *cobra.Command, err error, forceJSON bool) {
276293
}
277294
}
278295

296+
func exitCodeForError(err error) int {
297+
if err == nil {
298+
return exitCodeSuccess
299+
}
300+
301+
switch jsonErrorCode(err) {
302+
case jsonErrorCodeAppKeyRequired,
303+
jsonErrorCodeAuthExchangeFailed,
304+
jsonErrorCodeAuthRefreshFailed,
305+
jsonErrorCodeAuthRequired,
306+
jsonErrorCodeEnvTokenStillActive:
307+
return exitCodeAuthFailure
308+
case jsonErrorCodePermissionDenied:
309+
return exitCodePermissionDenied
310+
case jsonErrorCodeNotFound:
311+
return exitCodeNotFound
312+
case jsonErrorCodePathConflict:
313+
return exitCodeConflict
314+
case jsonErrorCodeRateLimited:
315+
return exitCodeRateLimited
316+
case jsonErrorCodeInvalidArguments,
317+
jsonErrorCodeStructuredOutputUnsupported,
318+
jsonErrorCodeUnknownCommand,
319+
jsonErrorCodeUnknownFlag:
320+
return exitCodeValidationError
321+
case jsonErrorCodePartialTransfer:
322+
return exitCodePartialTransfer
323+
default:
324+
return exitCodeGenericError
325+
}
326+
}
327+
279328
// outputJSONRequested is a narrow pre-parse fallback for errors that happen
280329
// before Cobra has resolved a command/flag context, such as unknown commands.
281330
func outputJSONRequested(args []string) bool {

0 commit comments

Comments
 (0)