build(docs-infra): update CLI option rendering (#26272)

PR Close #26272
This commit is contained in:
Pete Bacon Darwin 2018-10-05 13:50:29 +01:00 committed by Alex Rickabaugh
parent 6c530d3a85
commit 3f89aeb80a
2 changed files with 15 additions and 21 deletions

View File

@ -1,7 +1,8 @@
.cli-name, .cli-default { .cli-name {
font-weight: bold; font-weight: bold;
} }
.cli-option-syntax { .cli-option-syntax {
white-space: pre; white-space: pre;
} }

View File

@ -53,16 +53,12 @@
{% for option in options %} {% for option in options %}
<tr class="cli-option"> <tr class="cli-option">
<td> <td>
{% for type in option.types -%} <code class="cli-option-syntax">{$ renderOption(option.name, option.type, option.default, option.enum) $}</code>
{% 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 -%}
</td> </td>
<td> <td>
{$ option.description | marked $} {$ 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> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -71,26 +67,23 @@
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro bold(isBold, contents) -%} {%- macro renderOptionName(name) -%}
<span {% if isBold %}class="cli-default"{% endif %}>{$ contents $}</span> {% if name.length > 1 %}-{% endif %}-{$ name $}
{%- endmacro -%} {%- endmacro %}
{%- macro renderValues(values, default) -%} {%- macro renderValues(values, default) -%}
{% for value in values %}{$ bold(value==default, value) $}{% if not loop.last %}|{% endif %}{% endfor %} {$ values.join('|') $}
{%- endmacro -%} {%- endmacro -%}
{%- macro renderOption(name, alias, type, default, values) -%} {%- macro renderOption(name, type, default, values) -%}
{% set prefix = '--' if (name === alias and name.length > 1) else '-' %} {% set prefix = '--' if name.length > 1 else '-' %}
{%- if type === 'boolean' -%} {%- if type === 'boolean' and not values.length %}{$ prefix $}{$ name $}={$ renderValues([true, false], default) $}
{%- if not values.length %}{$ prefix $}{$ alias $}={$ renderValues([true, false], default) $}
{% endif -%}
{$ prefix $}{$ bold(default, alias) $}|{$ prefix $}{$ bold(not default, alias | cliNegate) $}
{%- elif values.length -%} {%- elif values.length -%}
{$ prefix $}{$ alias $}={$ renderValues(values, default) $} {$ prefix $}{$ name $}={$ renderValues(values, default) $}
{%- elif type === 'string' -%} {%- elif type === 'string' -%}
{$ prefix $}{$ alias $}=<var>{$ name $}</var> <var>{$ name $}</var>
{%- else -%} {%- else -%}
{$ prefix $}{$ alias $} {$ prefix $}{$ name $}
{%- endif -%} {%- endif -%}
{%- endmacro -%} {%- endmacro -%}