---
- name: Install additional packages
  hosts: all
  gather_facts: yes
  tasks:
    - block:
        - name: Install cliphist
          tags: cliphist
          command:
            cmd: go install go.senan.xyz/cliphist@latest

        # Avoid fzf.vim from distro repo
        - name: Install fzf
          tags: fzf
          command:
            cmd: go install github.com/junegunn/fzf@latest

        - name: Install glow
          tags: glow
          command:
            cmd: go install github.com/charmbracelet/glow@latest

        - name: Install koneko
          tags: koneko
          command:
            cmd: go install github.com/irevenko/koneko@latest

        - name: Install what-anime-cli
          tags: what-anime-cli
          command:
            cmd: go install github.com/irevenko/what-anime-cli@latest

        - name: Install wiki
          tags: wiki
          command:
            cmd: go install github.com/betapictoris/wiki@latest

        - name: Install lux
          tags: lux
          command:
            cmd: go install github.com/iawia002/lux@latest

        - name: Install vim-startuptime
          tags: vim
          command:
            cmd: go install github.com/rhysd/vim-startuptime@latest

        # NOTE: Clair server is required
        # - Install with 'go install github.com/quay/clair/v4/cmd/clair@latest' or use docker image
        # - Clair server requires a PostgreSQL instance
        # Default open on localhost:6060
        - name: Install clairctl
          tags: clair
          command:
            cmd: go install github.com/quay/clair/v4/cmd/clairctl@latest

        - name: Install helmfile
          tags: helmfile
          command:
            cmd: go install github.com/roboll/helmfile@latest

        - name: Install rancher-cli
          tags: rancher
          command:
            cmd: go install github.com/rancher/cli@latest

        - name: Clean go modcache
          command:
            cmd: go clean -modcache
      tags: go
      environment:
        GOPATH: '{{ ansible_env.HOME }}/.local/share/go'
        GOPROXY: direct

    - block:
        - name: Install selene
          tags: selene
          community.general.cargo:
            name: selene
            state: latest

        # texlab is not available on Cargo registry
        - name: Install texlab
          tags: texlab
          command:
            cmd: cargo install --git https://github.com/latex-lsp/texlab.git --locked --force
      tags: rust
      environment:
        CARGO_HOME: '{{ ansible_env.HOME }}/.local/share/cargo'

    - block:
        - name: Install mermaid-cli
          tags: mermaid
          yarn:
            name: '@mermaid-js/mermaid-cli'
            global: yes
            state: latest

        - name: Install antora
          tags: antora
          yarn:
            name: '{{ item }}'
            global: yes
            state: latest
          loop:
            - '@antora/cli'
            - '@antora/site-generator'
      environment:
        NPM_CONFIG_PREFIX: ~/.local/share/npm
      tags: [ yarn, npm ]

    - name: Install pyenv
      tags: pyenv
      environment:
        PYENV_ROOT: '{{ ansible_env.HOME }}/.local/share/pyenv'
      import_tasks: tasks/pyenv.yml

    - name: Install vagrant
      tags: vagrant
      vars:
        - vagrant_dir: ~/Code/vagrant
      import_tasks: tasks/vagrant.yml

    - block:
        - name: Install Anime4KCPP
          tags: anime4kcpp
          vars:
            - anime4kcpp_dir: ~/Code/Anime4KCPP
          import_tasks: tasks/anime4kcpp.yml

        - name: Install tt
          tags: tt
          vars:
            - tt_dir: ~/Code/tt
          import_tasks: tasks/tt.yml

        - name: Install zdict
          tags: zdict
          vars:
            zdict_venv_dir: ~/.config/zdict
          import_tasks: tasks/zdict.yml
      tags: custom
