2018-09-14 05:05:57 -04:00
{% macro renderSyntax(container, prefix) -%}
{% for name in container.names %}
2018-10-23 06:10:59 -04:00
< code-example hideCopy = "true" class = "no-box api-heading no-auto-link" > ng {%if prefix %}{$ prefix $} {% endif %}< span class = "cli-name" > {$ name $}< / span >
2018-09-14 05:05:57 -04:00
{%- 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" >
2018-10-23 06:10:59 -04:00
< td > < code class = "no-auto-link" > < < var > {$ option.name $}< / var > > < / code > < / td >
2018-09-14 05:05:57 -04:00
< 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 %}
2018-10-23 06:10:59 -04:00
< li > < code class = "no-auto-link" > < a class = "code-anchor" href = "#{$ subcommand.name $}-command" > {$ subcommand.name $}< / a > < / code > < / li >
2018-09-14 05:05:57 -04:00
{% 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 >
2018-10-23 06:10:59 -04:00
< code class = "cli-option-syntax no-auto-link" > {$ renderOption(option.name, option.type, option.default, option.enum) $}< / code >
2018-09-14 05:05:57 -04:00
< / td >
< td >
{$ option.description | marked $}
2018-10-23 06:10:59 -04:00
{% if option.default !== undefined %}< p > < span class = "cli-default" > Default:< / span > < code class = "no-auto-link" > {$ option.default $}< / code > < / p > {% endif %}
2018-10-05 08:50:29 -04:00
{% 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 %}
2018-09-14 05:05:57 -04:00
< / td >
< / tr >
{% endfor %}
< / tbody >
< / table >
{% endif %}
{% endmacro %}
2018-10-05 08:50:29 -04:00
{%- macro renderOptionName(name) -%}
{% if name.length > 1 %}-{% endif %}-{$ name $}
{%- endmacro %}
2018-09-14 05:05:57 -04:00
{%- macro renderValues(values, default) -%}
2018-10-05 08:50:56 -04:00
{%- set valString = values.join('|') -%}
{%- if valString.length > 15 %}< br > {% endif %}{$ valString $}
2018-09-14 05:05:57 -04:00
{%- endmacro -%}
2018-10-05 08:50:29 -04:00
{%- 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) $}
2018-09-14 05:05:57 -04:00
{%- elif values.length -%}
2018-10-05 08:50:29 -04:00
{$ prefix $}{$ name $}={$ renderValues(values, default) $}
2018-09-14 05:05:57 -04:00
{%- elif type === 'string' -%}
2018-10-05 08:50:56 -04:00
{$ prefix $}{$ name $}={% if name.length > 15 %}< br > {% endif %}< var > {$ name $}< / var >
2018-09-14 05:05:57 -04:00
{%- else -%}
2018-10-05 08:50:29 -04:00
{$ prefix $}{$ name $}
2018-09-14 05:05:57 -04:00
{%- 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 %}
2018-10-23 06:10:59 -04:00
< h3 > < code class = "no-auto-link" > < a id = "{$ subcommand.name $}-command" > < / a > {$ subcommand.name $}< / code > < / h3 >
2018-09-14 05:05:57 -04:00
{% 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 -%}