# brew tap gts/rs git@github.rackspace.com:SupportTools/homebrew-rs && brew update && brew install nscli
class Nscli < Formula
  include Language::Python::Virtualenv

  desc "Network Security Command-Line Interface"
  homepage "https://gh-pages.pvceng.rax.io/RSS-Engineering/nsi-nscli/"
  url "https://artifacts.rackspace.net/artifactory/api/pypi/pypi/packages/nscli/{{ version }}/nscli-{{ version }}.tar.gz"
  sha256 "{{ sha256 }}"
  head "https://github.rackspace.com/nsi/nscli.git", branch: "develop"

  depends_on "rust" => :build
  depends_on "python@3.9"

  # --- Begin Python Dependencies ---
{% for i in resources %}
  {{ i|indent(2) }}
{% endfor %}
  # --- End Python Dependencies ---

  def install
    venv = virtualenv_create(libexec, Formula["python@3.9"].opt_bin/"python3.9", without_pip: false)
    libexec.install("pip.conf")

    # --- Begin Python .whl Dependencies ---

    {% for i in whl_resources %}
    {{i}}
    {%- endfor %}

    # --- End Python Dependencies ---

    venv.pip_install resources
    venv.pip_install [buildpath]
    bin.install libexec/"bin/nscli"
    man1.install libexec/"share/man/man1/nscli.1.gz"
    man5.install libexec/"share/man/man5/nscli_settings.5.gz"
    bash_completion.install libexec/"share/bash-completion/completions/nscli"
    zsh_completion.install libexec/"share/zsh/vendor-completions/_nscli"
  end

  def caveats
    <<~EOS
      Settings are saved under:
        ~/Library/Application Support/nscli

      Logs are saved under:
        ~/Library/Logs/nscli

      Bash completion has been installed to:
        /usr/local/etc/bash_completion.d

      zsh completion has been installed to:
        /usr/local/share/zsh/site-functions

      Secrets are stored in the Keychain. All names will begin with "com.rackspace.nscli"

      Documentation: https://gh-pages.pvceng.rax.io/RSS-Engineering/nsi-nscli
    EOS
  end

  test do
    system bin/"nscli", "-v"
  end
end
