{% macro renderSyntax(container, prefix) -%} {% for name in container.names %} ng {%if prefix %}{$ prefix $} {% endif %}{$ name $} {%- for arg in container.positionalOptions %} <{$ arg.name $}>{% endfor %} {%- if container.namedOptions.length %} [options]{% endif -%} {% endfor %} {% endmacro %} {% macro renderArguments(arguments, level = 2) %} {% if arguments.length %} Arguments {% for option in arguments %} {% endfor %}
Argument Description
{$ option.name $} {$ option.description | marked $} {% if option.subcommands.length -%}

This option can take one of the following sub-commands:

{%- endif %}
{% endif %} {% endmacro %} {% macro renderNamedOptions(options, level = 2) %} {% if options.length %} Options {% for option in options %} {% endfor %}
Option Description
{% for type in option.types -%} {% for alias in option.names -%} {$ renderOption(option.name, alias, type, option.default, option.enum) $} {% if not loop.last %}
{% endif %} {% endfor -%} {% if not loop.last %}
{% endif %} {% endfor -%}
{$ option.description | marked $}
{% endif %} {% endmacro %} {% macro bold(isBold, contents) -%} {$ contents $} {%- 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 $}={$ name $} {%- else -%} {$ prefix $}{$ alias $} {%- endif -%} {%- endmacro -%} {%- macro renderSubcommands(container) -%} {% for command in container.positionalOptions %}{% if command.subcommands.length %}

{$ command.name | title $} commands

{% for subcommand in command.subcommands %}

{$ subcommand.name $}

{% 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 -%}