Determine output mode from flags, environment, and TTY detection. Priority: --pretty/--no-pretty > env vars > isatty() Note: per-command --json is handled separately in _should_json(). UNITY_CLI_JSON env var is checked here for global default.
(
pretty_flag: bool | None = None,
)
| 60 | |
| 61 | |
| 62 | def resolve_output_mode( |
| 63 | pretty_flag: bool | None = None, |
| 64 | ) -> OutputMode: |
| 65 | """Determine output mode from flags, environment, and TTY detection. |
| 66 | |
| 67 | Priority: --pretty/--no-pretty > env vars > isatty() |
| 68 | |
| 69 | Note: per-command --json is handled separately in _should_json(). |
| 70 | UNITY_CLI_JSON env var is checked here for global default. |
| 71 | """ |
| 72 | if pretty_flag is True: |
| 73 | return OutputMode.PRETTY |
| 74 | if pretty_flag is False: |
| 75 | return OutputMode.PLAIN |
| 76 | |
| 77 | # Environment variables (falsy values match Click's BoolParamType) |
| 78 | if os.environ.get("UNITY_CLI_JSON", "").strip().lower() not in _ENV_FALSY: |
| 79 | return OutputMode.JSON |
| 80 | if os.environ.get("UNITY_CLI_NO_PRETTY", "").strip().lower() not in _ENV_FALSY: |
| 81 | return OutputMode.PLAIN |
| 82 | if os.environ.get("NO_COLOR") is not None: |
| 83 | return OutputMode.PLAIN |
| 84 | |
| 85 | # TTY detection |
| 86 | if sys.stdout.isatty(): |
| 87 | return OutputMode.PRETTY |
| 88 | return OutputMode.PLAIN |
| 89 | |
| 90 | |
| 91 | _current_mode: OutputMode = OutputMode.PRETTY |