Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs-infra: aio CLI boolean options #26272

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion aio/src/styles/2-modules/_cli-pages.scss
@@ -1,7 +1,8 @@
.cli-name, .cli-default {
.cli-name {
font-weight: bold;
}

.cli-option-syntax {
white-space: pre;
}

36 changes: 15 additions & 21 deletions aio/tools/transforms/templates/cli/lib/cli.html
Expand Up @@ -20,7 +20,7 @@
<tbody>
{% for option in arguments %}
<tr class="cli-option">
<td><code>{$ option.name $}</code></td>
<td><code>&lt;<var>{$ option.name $}</var>&gt;</code></td>
<td>
{$ option.description | marked $}
{% if option.subcommands.length -%}
Expand Down Expand Up @@ -53,16 +53,12 @@
{% for option in options %}
<tr class="cli-option">
<td>
{% for type in option.types -%}
{% for alias in option.names -%}
<code class="cli-option-syntax">{$ renderOption(option.name, alias, type, option.default, option.enum) $}</code>
{% if not loop.last %}<br>{% endif %}
{% endfor -%}
{% if not loop.last %}<br>{% endif %}
{% endfor -%}
<code class="cli-option-syntax">{$ renderOption(option.name, option.type, option.default, option.enum) $}</code>
</td>
<td>
{$ option.description | marked $}
{% if option.default !== undefined %}<p><span class="cli-default">Default:</span> <code>{$ option.default $}</code></p>{% endif %}
{% if option.aliases.length %}<p><span class="cli-aliases">Aliases:</span> {% for alias in option.aliases %}{$ renderOptionName(alias) $}{% if not loop.last %}, {% endif %}{% endfor %}</p>{% endif %}
</td>
</tr>
{% endfor %}
Expand All @@ -71,26 +67,24 @@
{% endif %}
{% endmacro %}

{% macro bold(isBold, contents) -%}
<span {% if isBold %}class="cli-default"{% endif %}>{$ contents $}</span>
{%- endmacro -%}
{%- macro renderOptionName(name) -%}
{% if name.length > 1 %}-{% endif %}-{$ name $}
{%- endmacro %}

{%- macro renderValues(values, default) -%}
{% for value in values %}{$ bold(value==default, value) $}{% if not loop.last %}|{% endif %}{% endfor %}
{%- set valString = values.join('|') -%}
{%- if valString.length > 15 %}<br> {% endif %}{$ valString $}
{%- endmacro -%}

{%- macro renderOption(name, alias, type, default, values) -%}
{% set prefix = '--' if (name === alias and name.length > 1) else '-' %}
{%- if type === 'boolean' -%}
{%- if not values.length %}{$ prefix $}{$ alias $}={$ renderValues([true, false], default) $}
{% endif -%}
{$ prefix $}{$ bold(default, alias) $}|{$ prefix $}{$ bold(not default, alias | cliNegate) $}
{%- macro renderOption(name, type, default, values) -%}
{% set prefix = '--' if name.length > 1 else '-' %}
{%- if type === 'boolean' and not values.length %}{$ prefix $}{$ name $}={$ renderValues([true, false], default) $}
{%- elif values.length -%}
{$ prefix $}{$ alias $}={$ renderValues(values, default) $}
{$ prefix $}{$ name $}={$ renderValues(values, default) $}
{%- elif type === 'string' -%}
{$ prefix $}{$ alias $}=<var>{$ name $}</var>
{$ prefix $}{$ name $}={% if name.length > 15 %}<br> {% endif %}<var>{$ name $}</var>
{%- else -%}
{$ prefix $}{$ alias $}
{$ prefix $}{$ name $}
{%- endif -%}
{%- endmacro -%}

Expand Down