#compdef skbs
# Generated by Cyclopts (app.generate_completion(prog_name='skbs', shell='zsh'))
# then hand-patched: the "gen"/"g" TEMPLATE positional calls
# _skbs_complete_template_names (below) for a live list, since cyclopts can
# only generate static completions. If skbs's commands/options change,
# regenerate with the above call and re-apply that one patch (search for
# "_skbs_complete_template_names" below).

# Dynamic: list installed/local templates for TEMPLATE (cyclopts's static
# completion can't know these - see skbs._complete-templates)
_skbs_complete_template_names() {
  local -a candidates
  candidates=("${(@f)$(skbs _complete-templates "$PREFIX" 2>/dev/null)}")
  # -S '': no trailing space - template names can be paths (e.g. "cpp/class"),
  # let the user keep tabbing into subdirectories
  compadd -S '' -a candidates
}

_cyclopts_skbs() {
  local line state

  _arguments -C \
    '--help[Display this message and exit.]' \
    '-h[Display this message and exit.]' \
    '--version[Display application version.]' \
    '1: :->cmds' \
    '*::arg:->args'

  case $state in
    cmds)
      local -a commands
      commands=(
        'create-config:Create / reset to default the configuration file.'
        'config-path:Prints the path to the in-use configuration file.'
        'install-defaults:Install default provided templates'
        'i-d:Install default provided templates'
        'install:Install a new template.'
        'i:Install a new template.'
        'uninstall:Uninstall a template'
        'u:Uninstall a template'
        'list:List installed templates. If paths are given, search from them instead of the i…'
        'l:List installed templates. If paths are given, search from them instead of the i…'
        'ls:List installed templates. If paths are given, search from them instead of the i…'
        'gen:Generate a skeleton from a template.'
        'g:Generate a skeleton from a template.'
      )
      _describe -t commands 'command' commands
      ;;
    args)
      case $words[1] in
        create-config)
          _arguments \
            '1:--path' \
            '*--path[--path]:path' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        config-path)
          _arguments \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        install-defaults)
          _arguments \
            '1:--symlink' \
            '--symlink[--symlink]' \
            '-s[--symlink]' \
            '--no-symlink[--symlink]' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        i-d)
          _arguments \
            '1:--symlink' \
            '--symlink[--symlink]' \
            '-s[--symlink]' \
            '--no-symlink[--symlink]' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        install)
          _arguments \
            '1:--src' \
            '2:--symlink' \
            '3:--name' \
            '*--src[--src]:src' \
            '--symlink[--symlink]' \
            '-s[--symlink]' \
            '--no-symlink[--symlink]' \
            '*--name[--name]:name' \
            '*-n[--name]:n' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        i)
          _arguments \
            '1:--src' \
            '2:--symlink' \
            '3:--name' \
            '*--src[--src]:src' \
            '--symlink[--symlink]' \
            '-s[--symlink]' \
            '--no-symlink[--symlink]' \
            '*--name[--name]:name' \
            '*-n[--name]:n' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        uninstall)
          _arguments \
            '1:--name' \
            '*--name[--name]:name' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        u)
          _arguments \
            '1:--name' \
            '*--name[--name]:name' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        list)
          _arguments \
            '*:PATHS' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        l)
          _arguments \
            '*:PATHS' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        ls)
          _arguments \
            '*:PATHS' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        gen)
          _arguments \
            '1:if template starts with an '\''@'\'', it will look for an installed template. Else, i…:_skbs_complete_template_names' \
            '2:the output directory (parents will be created if needed)' \
            '*:argument passed to the template ( skbs gen <template_name> -- --help for more i…' \
            '*--template[if template starts with an '\''@'\'', it will look for an installed template. Else, i…]:template' \
            '*--dest[the output directory (parents will be created if needed)]:dest' \
            '--debug[--debug]' \
            '-g[--debug]' \
            '--no-debug[--debug]' \
            '--stdout[Only for single file templates \: output to stdout. --single-file is implied]' \
            '--no-stdout[Only for single file templates \: output to stdout. --single-file is implied]' \
            '--single-file[Authorize single file template for non installed templates.]' \
            '-s[Authorize single file template for non installed templates.]' \
            '--no-single-file[Authorize single file template for non installed templates.]' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
        g)
          _arguments \
            '1:if template starts with an '\''@'\'', it will look for an installed template. Else, i…:_skbs_complete_template_names' \
            '2:the output directory (parents will be created if needed)' \
            '*:argument passed to the template ( skbs gen <template_name> -- --help for more i…' \
            '*--template[if template starts with an '\''@'\'', it will look for an installed template. Else, i…]:template' \
            '*--dest[the output directory (parents will be created if needed)]:dest' \
            '--debug[--debug]' \
            '-g[--debug]' \
            '--no-debug[--debug]' \
            '--stdout[Only for single file templates \: output to stdout. --single-file is implied]' \
            '--no-stdout[Only for single file templates \: output to stdout. --single-file is implied]' \
            '--single-file[Authorize single file template for non installed templates.]' \
            '-s[Authorize single file template for non installed templates.]' \
            '--no-single-file[Authorize single file template for non installed templates.]' \
            '--help[Display this message and exit.]' \
            '-h[Display this message and exit.]' \
            '--version[Display application version.]'

          ;;
      esac
      ;;
  esac
}

# `#compdef skbs` above only auto-registers this when the file is loaded
# via the fpath+compinit autoload convention. Also register explicitly so
# it works when a user just `source`s this file directly (e.g. from
# .zshrc), like the old script used to.
compdef _cyclopts_skbs skbs

