<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
{% assign tool_name = include.tool %}
{% assign tool = site.data.cli[tool_name] %}
{% assign commands = tool.commands %}
<div class="card cli">
  <h2 class="cli-command-title is-right" id="{{ tool_name }}">
    <code class="highlighter-rouge">{{ tool_name }}</code>
  </h2>
  <div class="card-content">
    {{ tool.description | markdownify }}
    <h5>Usage</h5>
    <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> {{ tool_name }}{% if tool.commands %} <span class="command">command</span>{% endif %}{% if command.options %} <span class="options">options</span>{% endif %}</code></pre></div>
    {% if commands %}
    <h5>Commands</h5>
    <ul>
      {% for command in commands %}
      <li>
        <a href="#{{ tool_name }}-{{ command.name }}">
          <code class="highlighter-rouge">{{ command.name }}</code>
        </a>
      </li>
      {% endfor %} <!-- for command in commands -->
    </ul>
    {% if tool.options %}{% assign options = tool.options %}
    <h5>Options</h5>
    <table class="options-table">
      <thead>
        <tr>
          <th>Flag</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
        <tbody>
          {% for option in options %}
          <tr>
            <td nowrap>
              {% assign flags = option.flags | split: ", " %}
              {% for flag in flags %}
              <code class="highlighter-rouge">{{ flag }}</code>
              {% unless forloop.last %}, {% endunless %}
              {% endfor %} <!-- for flag in option.flags -->
            </td>
            <td>{{ option.description | markdownify }}</td>
            <td>
              {% if option.default %}{{ option.default | markdownify }}{% endif %}
            </td>
          </tr>
          {% endfor %} <!-- for option in options -->
        </tbody>
      </thead>
    </table>
    {% endif %} <!-- if tool.options -->
    {% if tool.example %}
    <h5>Example</h5>
    <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> <span>{{ tool.example }}</span></code></pre></div>
    {% endif %} <!-- if tool.example -->
    {% endif %} <!-- if commands -->

    {% if tool.env_vars %}{% assign vars = tool.env_vars %}
    <h5>Environment variables</h5>
    <p>
      The table below lists the environment variables that you can use to configure the <code class="highlighter-rouge">{{ tool_name }}</code> tool.
    </p>
    <table>
      <thead>
        <th>Variable</th>
        <th>Description</th>
        <th>Default</th>
      </thead>
      <tbody>
        {% for var in vars %}
        <tr>
          <td><code class="highlighter-rouge">{{ var.name }}</code></td>
          <td>{{ var.description }}</td>
          <td>{% if var.default %}<code class="highlighter-rouge">{{ var.default }}</code>{% endif %}</td>
        </tr>
        {% endfor %} <!-- for var in vars -->
      </tbody>
    </table>
    {% endif %} <!-- if tool.env_vars -->

    {% for command in commands %}{% assign subcommands = command.subcommands %}
    <div class="card cli-command">
      <h3 class="cli-command-title" id="{{ tool_name }}-{{ command.name }}">
        <code class="highlighter-rouge">{{ command.name }}</code>
      </h3>
      <div class="card-content">
        {{ command.description | markdownify }}
        <h5>Usage</h5>
        <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> {{ tool_name }} {{ command.name }}{% if command.subcommands %} <span class="command">subcommand</span>{% endif %}{% if command.argument %} <span class="command">{{ command.argument }}</span>{% endif %}{% if command.options %} <span class="options">options</span>{% endif %}</code></pre></div>
        {% if command.options %}{% assign options = command.options %}
        <h5>Options</h5>
        <table class="options-table">
          <thead>
            <tr>
              <th>Flag</th>
              <th>Description</th>
              <th>Default</th>
            </tr>
            <tbody>
              {% for option in options %}
              <tr>
                <td nowrap>
                  {% assign flags = option.flags | split: ", " %}
                  {% for flag in flags %}
                  <code class="highlighter-rouge">{{ flag }}</code>
                  {% unless forloop.last %}, {% endunless %}
                  {% endfor %} <!-- for flag in option.flags -->
                </td>
                <td>{{ option.description | markdownify }}</td>
                <td>
                  {% if option.default %}{{ option.default | markdownify }}{% endif %}
                </td>
              </tr>
              {% endfor %} <!-- for option in options -->
            </tbody>
          </thead>
        </table>
        {% endif %} <!-- if command.options -->
        {% if command.example %}
        <h5>Example</h5>
        <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> <span>{{ command.example }}</span></code></pre></div>
        {% endif %} <!-- if command.example -->

        {% if subcommands %}
        <h5>Subcommands</h5>
        <ul>
          {% for subcommand in subcommands %}
          <li>
            <a href="#{{ tool_name }}-{{ command.name }}-{{ subcommand.name }}">
              <code class="highlighter-rouge">{{ subcommand.name }}</code>
            </a>
          </li>
          {% endfor %} <!-- for subcommand in subcommands -->
        </ul>

        {% for subcommand in subcommands %}
        <div class="card cli-subcommand">
          <h4 class="card-header-title" id="{{ tool_name }}-{{ command.name }}-{{ subcommand.name }}"><code class="highlighter-rouge">{{ subcommand.name }}</code></h4>
          <div class="card-content">
            <p>{{ subcommand.description }}</p>
            <h5>Usage</h5>
            <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> {{ tool_name }} {{ command.name }} {{ subcommand.name }}{% if subcommand.argument %} <span class="command">{{ subcommand.argument }}</span>{% endif %}{% if subcommand.options %} <span class="options">options</span>{% endif %}</code></pre></div>
            {% if subcommand.options %}{% assign options = subcommand.options %}
            <h5>Options</h5>
            <table class="options-table">
              <thead>
                <tr>
                  <th>Flag</th>
                  <th>Description</th>
                  <th>Default</th>
                </tr>
                <tbody>
                  {% for option in options %}
                  <tr>
                    <td nowrap>
                      {% assign flags = option.flags | split: ", " %}
                      {% for flag in flags %}
                      <code class="highlighter-rouge">{{ flag }}</code>
                      {% unless forloop.last %}, {% endunless %}
                      {% endfor %} <!-- for flag in option.flags -->
                    </td>
                    <td>{{ option.description | markdownify }}</td>
                    <td>
                      {% if option.default %}{{ option.default | markdownify }}{% endif %}
                    </td>
                  </tr>
                  {% endfor %} <!-- for option in options -->
                </tbody>
              </thead>
            </table>
            {% endif %} <!-- if subcommand.options -->
            {% if subcommand.example %}
            <h5>Example</h5>
            <div class="language-shell highlighter-rouge"><pre class="highlight"><code><span class="gp">$</span> <span>{{ subcommand.example }}</span></code></pre></div>
            {% endif %} <!-- if command.example -->
          </div>
        </div>
      {% endfor %} <!-- for subcommand in subcommands -->
      {% endif %}
      </div>
    </div>
    {% endfor %} <!-- for command in commands -->
  </div>
</div>
