aeat.core.click_context module¶
Shared click context helpers safe to import from any layer.
The helpers walk the active click.Context chain to surface root-level
CLI flags (e.g. --json) without forcing callers to thread the context
object explicitly. They live in core so domain code can call
json_output_requested(), current_cli_flag(), or
context_chain_requests_json() without inverting the dependency direction
onto entrypoints.cli. Terminal error handlers that have no live
context can fall back to argv_requests_json().
This module answers output-mode questions only. It is not an active-profile, bucket-session, or command-dispatch state source; those boundaries remain in the CLI bootstrap and storage/session helpers that own them.
- current_cli_flag(name)[source]¶
Return the boolean value of
namefrom any ancestor context’sobjdict.Walks the
click.Contextparent chain looking for the firstctx.objmapping that carriesname; the truthiness of the associated value is returned. ReturnsFalsewhen no context is active or no ancestor carries the flag. This helper intentionally readsctx.objonly; option values stored inctx.paramsare handled byjson_output_requested().
- json_output_requested()[source]¶
Return
Truewhen the active context requests JSON output.Checks every recognised JSON flag spelling —
--json,--as-json,--json-out,--json-output— across the Click context chain. It also recognises the root AEAT--format jsonoption, including Typer’s Python-facingformat_parameter name. The variant tolerance lets callers register the flag under whichever Python parameter name fits their command without breaking the output-mode probe. For terminal handlers without a live current context, usecontext_chain_requests_json()when an exception carries a context orargv_requests_json()as the last-resort argv parser.- Return type:
- context_chain_requests_json(ctx)[source]¶
Return
Truewhenctxor any ancestor requests JSON output.Companion to
json_output_requested()for call sites where the context stack is already unwound (e.g. the root group’s terminal exception handler, where aclick.UsageErrorcarries its parse-time context onexc.ctxbut no context is “current”). Accepts either Click runtime’s context object structurally.
- argv_requests_json(argv)[source]¶
Return
Truewhen rawargvtokens request JSON output.Last-resort probe for terminal handlers that have neither an active context stack nor an exception-carried context (e.g. a crash before or outside command dispatch). Recognises
--format json,--format=json, and the--jsonflag family. It is syntactic only: command parsing and value validation still belong to Click/Typer.