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)
| 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. |
| 388 | func 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 |
no outgoing calls