{#-
CLI Command Options Component

Renders command options using the unified parameter table.
Handles both global and command-specific options safely.
-#}

{% from 'macros/safe_macros.md.jinja2' import safe_render, safe_for %}
{% from 'macros/parameter_table.md.jinja2' import cli_options %}

{% set options = element.children | selectattr('element_type', 'equalto', 'option') | list %}

{% if options %}
## Options

{% call(current_item) safe_for(options, "*No options available.*") %}
{% call safe_render("option", current_item) %}
### `{{ current_item.name }}`

{% if current_item.metadata.short_name %}
**Short form:** `-{{ current_item.metadata.short_name }}`
{% endif %}

{% if current_item.description %}
{{ current_item.description }}
{% else %}
*No description provided.*
{% endif %}

{% if current_item.metadata.type %}
**Type:** `{{ current_item.metadata.type }}`
{% endif %}

{% if current_item.metadata.default %}
{% set default_str = current_item.metadata.default | string %}
{% if default_str and default_str not in ['None', '', 'null'] and 'Sentinel' not in default_str %}
**Default:** `{{ current_item.metadata.default }}`
{% endif %}
{% endif %}

{% if current_item.metadata.required %}
:::{note}
This option is required.
:::
{% endif %}

{% if current_item.metadata.choices %}
**Choices:** {% for choice in current_item.metadata.choices %}`{{ choice }}`{% if not loop.last %}, {% endif %}{% endfor %}
{% endif %}

{% endcall %}
{% endcall %}
{% endif %}
