MCPcopy Create free account
hub / github.com/dropbox/dbxcli / outputJSONRequested

Function outputJSONRequested

cmd/output.go:388–412  ·  view source on GitHub ↗

outputJSONRequested is a narrow pre-parse fallback for errors that happen before Cobra has resolved a command/flag context, such as unknown commands.

(args []string)

Source from the content-addressed store, hash-verified

386// outputJSONRequested is a narrow pre-parse fallback for errors that happen
387// before Cobra has resolved a command/flag context, such as unknown commands.
388func outputJSONRequested(args []string) bool {
389 jsonRequested := false
390 for i := 0; i < len(args); i++ {
391 arg := args[i]
392 switch arg {
393 case "--":
394 return jsonRequested
395 case "--output=json":
396 jsonRequested = true
397 case "--output=text":
398 jsonRequested = false
399 case "--output":
400 if i+1 >= len(args) {
401 return false
402 }
403 jsonRequested = args[i+1] == "json"
404 i++
405 default:
406 if strings.HasPrefix(arg, "--output=") {
407 jsonRequested = strings.TrimPrefix(arg, "--output=") == "json"
408 }
409 }
410 }
411 return jsonRequested
412}
413
414// jsonErrorCode derives stable script-facing codes from existing CLI errors.
415// Prefer coded errors for dbxcli-owned validation failures. String matching is

Callers 3

ExecuteFunction · 0.85
rawArgsRequestJSONHelpFunction · 0.85
TestOutputJSONRequestedFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestOutputJSONRequestedFunction · 0.68