Helpers
provide.foundation.cli.helpers
¶
TODO: Add module docstring.
Classes¶
Functions¶
build_attributes_from_args
¶
build_attributes_from_args(
json_attrs: str | None, attr: tuple[str, ...]
) -> tuple[dict[str, Any], int]
Build attributes dictionary from JSON and key=value arguments.
Uses the parsers module for consistent type inference and parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_attrs
|
str | None
|
JSON string of attributes |
required |
attr
|
tuple[str, ...]
|
Tuple of key=value attribute strings |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], int]
|
Tuple of (attributes dict, error_code). Error code is 0 on success. |
Source code in provide/foundation/cli/helpers.py
format_duration
¶
Format duration in seconds to human-readable string.
Delegates to formatting.numbers.format_duration() with short format and adds spaces between components for CLI readability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Duration in seconds |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted duration string (e.g., "1h 23m 45s", "45s", "1.5s") |
Source code in provide/foundation/cli/helpers.py
get_client_from_context
¶
Get OpenObserve client from Click context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Any
|
Click context object |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any | None, int]
|
Tuple of (client, error_code). Error code is 0 on success. |
Source code in provide/foundation/cli/helpers.py
get_message_from_stdin
¶
Get message from stdin if available.
Returns:
| Type | Description |
|---|---|
str | None
|
Tuple of (message, error_code). If successful, error_code is 0. |
int
|
If stdin is a TTY (no piped input), returns (None, 1). |
Source code in provide/foundation/cli/helpers.py
parse_filter_string
¶
Parse filter string into key-value dictionary.
Uses the parsers module for consistent parsing behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_str
|
str
|
Filter string in format 'key1=value1,key2=value2' |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of filter key-value pairs |
Source code in provide/foundation/cli/helpers.py
requires_click
¶
Decorator to ensure Click is available for CLI commands.
Replaces the boilerplate if _HAS_CLICK / else ImportError stub pattern.
Example
@requires_click def my_command(*args, **kwargs): # Command implementation pass
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[P, R]
|
CLI command function to wrap |
required |
Returns:
| Type | Description |
|---|---|
Callable[P, R]
|
Wrapped function that raises ImportError if Click is not available |