111 lines
3.7 KiB
HTML
111 lines
3.7 KiB
HTML
|
{% macro renderSyntax(container, prefix) -%}
|
||
|
{% for name in container.names %}
|
||
|
<code-example hideCopy="true" class="no-box api-heading">ng {%if prefix %}{$ prefix $} {% endif %}<span class="cli-name">{$ name $}</span>
|
||
|
{%- for arg in container.positionalOptions %} <<var>{$ arg.name $}</var>>{% endfor %}
|
||
|
{%- if container.namedOptions.length %} [<var>options</var>]{% endif -%}
|
||
|
</code-example>
|
||
|
{% endfor %}
|
||
|
{% endmacro %}
|
||
|
|
||
|
{% macro renderArguments(arguments, level = 2) %}
|
||
|
{% if arguments.length %}
|
||
|
<h{$ level $} class="no-anchor">Arguments</h{$ level $}>
|
||
|
<table class="is-full-width list-table property-table">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>Argument</th>
|
||
|
<th>Description</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
{% for option in arguments %}
|
||
|
<tr class="cli-option">
|
||
|
<td><code>{$ option.name $}</code></td>
|
||
|
<td>
|
||
|
{$ option.description | marked $}
|
||
|
{% if option.subcommands.length -%}
|
||
|
<p>This option can take one of the following <a href="#{$ option.name $}-commands">sub-commands</a>:<p>
|
||
|
<ul>
|
||
|
{% for subcommand in option.subcommands %}
|
||
|
<li><code><a class="code-anchor" href="#{$ subcommand.name $}-command">{$ subcommand.name $}</a></code></li>
|
||
|
{% endfor %}
|
||
|
</ul>
|
||
|
{%- endif %}
|
||
|
</td>
|
||
|
</tr>
|
||
|
{% endfor %}
|
||
|
</tbody>
|
||
|
</table>
|
||
|
{% endif %}
|
||
|
{% endmacro %}
|
||
|
|
||
|
{% macro renderNamedOptions(options, level = 2) %}
|
||
|
{% if options.length %}
|
||
|
<h{$ level $} class="no-anchor">Options</h{$ level $}>
|
||
|
<table class="is-full-width list-table property-table">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>Option</th>
|
||
|
<th>Description</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
{% 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 -%}
|
||
|
</td>
|
||
|
<td>
|
||
|
{$ option.description | marked $}
|
||
|
</td>
|
||
|
</tr>
|
||
|
{% endfor %}
|
||
|
</tbody>
|
||
|
</table>
|
||
|
{% endif %}
|
||
|
{% endmacro %}
|
||
|
|
||
|
{% macro bold(isBold, contents) -%}
|
||
|
<span {% if isBold %}class="cli-default"{% endif %}>{$ contents $}</span>
|
||
|
{%- endmacro -%}
|
||
|
|
||
|
{%- macro renderValues(values, default) -%}
|
||
|
{% for value in values %}{$ bold(value==default, value) $}{% if not loop.last %}|{% endif %}{% endfor %}
|
||
|
{%- 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) $}
|
||
|
{%- elif values.length -%}
|
||
|
{$ prefix $}{$ alias $}={$ renderValues(values, default) $}
|
||
|
{%- elif type === 'string' -%}
|
||
|
{$ prefix $}{$ alias $}=<var>{$ name $}</var>
|
||
|
{%- else -%}
|
||
|
{$ prefix $}{$ alias $}
|
||
|
{%- endif -%}
|
||
|
{%- endmacro -%}
|
||
|
|
||
|
{%- macro renderSubcommands(container) -%}
|
||
|
{% for command in container.positionalOptions %}{% if command.subcommands.length %}
|
||
|
<h2><a id="{$ command.name $}-commands"></a>{$ command.name | title $} commands</h2>
|
||
|
{% for subcommand in command.subcommands %}
|
||
|
<h3><code><a id="{$ subcommand.name $}-command"></a>{$ subcommand.name $}</code></h3>
|
||
|
{% for name in container.names %}
|
||
|
{$ renderSyntax(subcommand, name) $}
|
||
|
{% endfor %}
|
||
|
{$ subcommand.description | marked $}
|
||
|
{# for now we assume that commands do not have further sub-commands #}
|
||
|
{$ renderArguments(subcommand.positionalOptions, 4) $}
|
||
|
{$ renderNamedOptions(subcommand.namedOptions, 4) $}
|
||
|
{% endfor %}
|
||
|
{% endif %}{% endfor %}
|
||
|
{%- endmacro -%}
|