judgevet.adapters.inbound.cli
Status: draft.
judgevet.adapters.inbound.cli
Inbound CLI adapter.
The command wrapper propagates failure status to the process while helpers return integer codes and the composition root closes its adapter. Explicit file and stdin sources are validated before adapter construction. Explicit policies use a separate composition path and distinguish unmet policy from errors. Both paths resolve credential sources once before adapter construction. They render rate limits as handled failures and configure stderr logging.
Examples:
from judgevet.adapters.inbound.cli import app
# Run CLI: judgevet --help
See Also
- judgevet.adapters.inbound.settings: Settings for configuration
- judgevet.adapters.outbound.http: HTTP adapter
- judgevet.ports: Port protocol
- judgevet.domain.response: Response types
- judgevet.domain.questions: Question types
- judgevet.domain.answers: Answer types
- judgevet.domain.errors: Error types
build_response_data(response)
Build response data dictionary from a typed SystemOneResponse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SystemOneResponse
|
Typed SystemOneResponse from the adapter. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response data dictionary for output. |
cli_main()
CLI entry point for backward compatibility.
Parses sys.argv with parse_args and delegates to main.
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 for success, 1 for error. |
format_answer(name, answer)
Format an answer as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Question name. |
required |
answer
|
Answer
|
The answer object. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the answer. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the answer type is unknown. |
main(state=typer.Argument(..., help='State to evaluate (JSON string or text)'), questions=typer.Argument(..., help='Questions as JSON string'), model=typer.Option('jev-latest', help='Model to use'), api_key=typer.Option(None, help='TypeSafe API key'), json_output=typer.Option(False, '--json', help='Output as JSON'))
Call the Jev System One API.
Reads Settings and configures stderr logging. An explicit --api-key overrides the selected credential source. Resolves it once as a wrapped key. Constructs HTTPSystemOneAdapter once with the settings timeout, gateway fields, network options and retry limits, then calls run_cli. Configuration failures produce a generic handled diagnostic. Closes the adapter in finally. The command wrapper supplies separate help and propagates failure status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
State to evaluate (JSON string or text). |
Argument(..., help='State to evaluate (JSON string or text)')
|
questions
|
str
|
Questions as JSON string. |
Argument(..., help='Questions as JSON string')
|
model
|
str
|
Model to use. |
Option('jev-latest', help='Model to use')
|
api_key
|
str | None
|
TypeSafe API key. |
Option(None, help='TypeSafe API key')
|
json_output
|
bool
|
Whether to output as JSON. |
Option(False, '--json', help='Output as JSON')
|
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 for success, 1 for error. |
output_response(response_data, as_json)
Output response data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_data
|
dict[str, Any]
|
Response data dictionary. |
required |
as_json
|
bool
|
Whether to output as JSON. |
required |
parse_args()
Parse command line arguments.
This function is kept for backward compatibility with tests. It creates a temporary argparse parser to parse arguments.
Returns:
| Type | Description |
|---|---|
Any
|
Parsed command line arguments. |
parse_questions(questions_json)
Parse questions from JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
questions_json
|
str
|
JSON string defining questions. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary mapping question names to question objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown question type is encountered. |
run_cli(port, state, questions, model='jev-latest', json_output=typer.Option(False, '--json', help='Output as JSON'))
Run the CLI with a port and render handled errors, including rate limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
SystemOnePort
|
The port used for API calls. |
required |
state
|
str
|
State to evaluate (JSON string or text). |
required |
questions
|
str
|
Questions as JSON string. |
required |
model
|
str
|
Model to use. Defaults to "jev-latest". |
'jev-latest'
|
json_output
|
bool
|
Whether to output as JSON. |
Option(False, '--json', help='Output as JSON')
|
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 for success, 1 for judgment errors. |