{%- if cmd.before_help %}{{ cmd.before_help }}

{% elif spec.before_help %}{{ spec.before_help }}

{% endif -%}
{%- if root %}
{%- if spec.name and spec.version %}{{ spec.name }} {{ spec.version }}
{% elif spec.version %}{{ spec.bin }} {{ spec.version }}
{% endif -%}
{%- if spec.about %}{{ spec.about }}

{% endif -%}
{%- else -%}
{%- if cmd.help %}{{ cmd.help }}

{% endif -%}
{%- endif -%}
{%- if cmd.deprecated or cmd.deprecated_warn_at or cmd.deprecated_remove_at %}
[deprecated:{% if cmd.deprecated %} {{ cmd.deprecated }}{% endif %}{% if cmd.deprecated_warn_at %}{% if cmd.deprecated %};{% endif %} warns at {{ cmd.deprecated_warn_at }}{% endif %}{% if cmd.deprecated_remove_at %}{% if cmd.deprecated or cmd.deprecated_warn_at %};{% endif %} removed at {{ cmd.deprecated_remove_at }}{% endif %}]

{%- endif -%}{{ mark_usage }}
{%- if cmd.flatten_help and cmd.flattened_usage %}
{%- for usage in cmd.flattened_usage %}
{% if loop.first %}Usage: {% else %}       {% endif %}{{ (spec.bin ~ " " ~ usage) | trim }}
{%- endfor %}
{%- else -%}
Usage: {{ (spec.bin ~ " " ~ cmd.usage) | trim }}
{%- endif %}{{ mark_commands }}

{%- if cmd.subcommands and not cmd.flatten_help %}
{%- set next_line_help = cmd.next_line_help %}
{%- for group in cmd.subcommand_groups %}

{{ group.heading | default(value=cmd.subcommand_help_heading | default(value="Commands")) }}:
{%- for cmd in group.items %}
  {{ cmd.usage | trim }}
{%- if cmd.deprecated or cmd.deprecated_warn_at or cmd.deprecated_remove_at %} [deprecated:{% if cmd.deprecated %} {{ cmd.deprecated }}{% endif %}{% if cmd.deprecated_warn_at %}{% if cmd.deprecated %};{% endif %} warns at {{ cmd.deprecated_warn_at }}{% endif %}{% if cmd.deprecated_remove_at %}{% if cmd.deprecated or cmd.deprecated_warn_at %};{% endif %} removed at {{ cmd.deprecated_remove_at }}{% endif %}]{%- endif %}
{%- if cmd.aliases %} [aliases: {{ cmd.aliases | join(sep=", ") }}]{% endif %}
{%- if cmd.help %}{% if next_line_help %}
    {{ cmd.help | indent(width=4) }}{% else %}  {{ cmd.help }}{% endif %}{%- endif %}
{%- endfor %}
{%- if not group.heading and show_help_subcommand %}
{% if next_line_help %}  help
    Print this message or the help of the given subcommand(s){% else %}  help  Print this message or the help of the given subcommand(s){% endif %}
{%- endif %}
{%- endfor %}
{%- endif %}{{ mark_args }}

{%- for group in cmd.arg_groups %}

{{ group.heading | default(value="Arguments") }}:
{%- for arg in group.items %}
  {% if arg.help %}{% if cmd.next_line_help %}{{ arg.usage | trim }}
    {{ arg.help | indent(width=4) }}{% else %}{{ arg.usage | trim | ljust(width=arg.usage_col_width) }}  {{ arg.help }}{% endif %}{% else %}{{ arg.usage | trim }}{% endif %}
{%- if cmd.next_line_help %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %}
    [possible values: {{ arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %}
    [choices env: {{ arg.choices.env }}]{%- endif %}
{%- if not arg.hide_env and arg.env %}
    [env: {{ arg.env }}]{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %}
    [env fallback: {{ env }}]{%- endfor %}{% for env in arg.deprecated_env %}
    [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %}
    (default: {{ arg.default | join(sep=", ") }}){%- endif %}
{%- else %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %} [{{ arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %} [choices env: {{ arg.choices.env }}]{%- endif %}
{%- if not arg.hide_env and arg.env %} [env: {{ arg.env }}]{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %} [env fallback: {{ env }}]{%- endfor %}{% for env in arg.deprecated_env %} [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %} (default: {{ arg.default | join(sep=", ") }}){%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}{{ mark_flags }}

{%- for group in cmd.flag_groups %}

{{ group.heading | default(value="Flags") }}:
{%- for flag in group.items %}
  {% if flag.help %}{% if cmd.next_line_help %}{{ flag.display_usage }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
    {{ flag.help | indent(width=4) }}{% else %}{{ flag.display_usage | ljust(width=flag.usage_col_width) }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}  {{ flag.help }}{% endif %}{% else %}{{ flag.display_usage }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}{% endif %}
{%- if cmd.next_line_help %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
    [possible values: {{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
    [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %}
    [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
    [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %}
    [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
    (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- else %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %} [{{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %} [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %} [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %} [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %} [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %} (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}{% if cmd.next_line_help %}
    {% else %} {% endif %}[deprecated:{% if flag.deprecated %} {{ flag.deprecated }}{% endif %}{% if flag.deprecated_warn_at %}{% if flag.deprecated %};{% endif %} warns at {{ flag.deprecated_warn_at }}{% endif %}{% if flag.deprecated_remove_at %}{% if flag.deprecated or flag.deprecated_warn_at %};{% endif %} removed at {{ flag.deprecated_remove_at }}{% endif %}]{%- endif %}
{%- endfor %}
{%- endfor %}

{%- if global_flags %}

Global flags:
{%- for flag in global_flags %}
  {% if flag.help %}{% if cmd.next_line_help %}{{ flag.display_usage }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
    {{ flag.help | indent(width=4) }}{% else %}{{ flag.display_usage | ljust(width=flag.usage_col_width) }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}  {{ flag.help }}{% endif %}{% else %}{{ flag.display_usage }}{% if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}{% endif %}
{%- if cmd.next_line_help %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
    [possible values: {{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
    [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %}
    [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
    [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %}
    [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
    (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- else %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %} [{{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %} [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %} [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %} [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %} [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %} (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}{% if cmd.next_line_help %}
    {% else %} {% endif %}[deprecated:{% if flag.deprecated %} {{ flag.deprecated }}{% endif %}{% if flag.deprecated_warn_at %}{% if flag.deprecated %};{% endif %} warns at {{ flag.deprecated_warn_at }}{% endif %}{% if flag.deprecated_remove_at %}{% if flag.deprecated or flag.deprecated_warn_at %};{% endif %} removed at {{ flag.deprecated_remove_at }}{% endif %}]{%- endif %}
{%- endfor %}
{%- endif %}{{ mark_flattened }}

{%- if cmd.flatten_help %}
{%- for sub in cmd.flattened_subcommands %}

{{ sub.full_cmd | join(sep=" ") }}:
{%- if sub.help %}
{{ sub.help | trim }}
{%- endif %}
{%- if sub.deprecated or sub.deprecated_warn_at or sub.deprecated_remove_at %}
[deprecated:{% if sub.deprecated %} {{ sub.deprecated }}{% endif %}{% if sub.deprecated_warn_at %}{% if sub.deprecated %};{% endif %} warns at {{ sub.deprecated_warn_at }}{% endif %}{% if sub.deprecated_remove_at %}{% if sub.deprecated or sub.deprecated_warn_at %};{% endif %} removed at {{ sub.deprecated_remove_at }}{% endif %}]
{%- endif %}
{%- for group in sub.arg_groups %}
{%- for arg in group.items %}
  {% if arg.help %}{% if sub.flattened_next_line_help %}{{ arg.usage | trim }}
    {{ arg.help | indent(width=4) }}{% else %}{{ arg.usage | trim | ljust(width=arg.usage_col_width) }}  {{ arg.help }}{% endif %}{% else %}{{ arg.usage | trim }}{% endif %}
{%- if sub.flattened_next_line_help %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %}
    [possible values: {{ arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %}
    [choices env: {{ arg.choices.env }}]{%- endif %}
{%- if not arg.hide_env and arg.env %}
    [env: {{ arg.env }}]{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %}
    [env fallback: {{ env }}]{%- endfor %}{% for env in arg.deprecated_env %}
    [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %}
    (default: {{ arg.default | join(sep=", ") }}){%- endif %}
{%- else %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %} [{{ arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %} [choices env: {{ arg.choices.env }}]{%- endif %}
{%- if not arg.hide_env and arg.env %} [env: {{ arg.env }}]{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %} [env fallback: {{ env }}]{%- endfor %}{% for env in arg.deprecated_env %} [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %} (default: {{ arg.default | join(sep=", ") }}){%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- for group in sub.flag_groups %}
{%- for flag in group.items %}
  {% if flag.help %}{% if sub.flattened_next_line_help %}{{ flag.display_usage }}
    {{ flag.help | indent(width=4) }}{% else %}{{ flag.display_usage | ljust(width=flag.usage_col_width) }}  {{ flag.help }}{% endif %}{% else %}{{ flag.display_usage }}{% endif %}
{%- if sub.flattened_next_line_help %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
    [possible values: {{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
    [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %}
    [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
    [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %}
    [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
    (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- else %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %} [{{ flag.arg.choices.choices | join(sep=", ") }}]{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %} [choices env: {{ flag.arg.choices.env }}]{%- endif %}
{%- if not flag.hide_env and flag.env %} [env: {{ flag.env }}]{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %} [env fallback: {{ env }}]{%- endfor %}{% for env in flag.deprecated_env %} [deprecated env: {{ env }}]{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %} (default: {{ flag.default | join(sep=", ") }}){%- endif %}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}{% if sub.flattened_next_line_help %}
    {% else %} {% endif %}[deprecated:{% if flag.deprecated %} {{ flag.deprecated }}{% endif %}{% if flag.deprecated_warn_at %}{% if flag.deprecated %};{% endif %} warns at {{ flag.deprecated_warn_at }}{% endif %}{% if flag.deprecated_remove_at %}{% if flag.deprecated or flag.deprecated_warn_at %};{% endif %} removed at {{ flag.deprecated_remove_at }}{% endif %}]{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endif %}{{ mark_after_help }}

{%- if cmd.examples %}

Examples:
{%- for example in cmd.examples %}
{%- if example.header %}
  {{ example.header }}:
{%- endif %}
    $ {{ example.code }}
{%- endfor %}
{%- elif spec.examples %}

Examples:
{%- for example in spec.examples %}
{%- if example.header %}
  {{ example.header }}:
{%- endif %}
    $ {{ example.code }}
{%- endfor %}
{%- endif %}

{%- if cmd.after_help %}

{{ cmd.after_help }}
{%- elif spec.after_help %}

{{ spec.after_help }}
{%- endif -%}
