#compdef bombadil

autoload -U is-at-least

_bombadil() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_bombadil_commands" \
"*::: :->Toml Bombadil" \
&& ret=0
    case $state in
    (Toml Bombadil)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:bombadil-command-$line[1]:"
        case $line[1] in
            (install)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'::config -- Path to your dotfile directory:_files' \
&& ret=0
;;
(clone)
_arguments "${_arguments_options[@]}" : \
'-r+[Remote repository address, either http or ssh]:REMOTE:_default' \
'--remote=[Remote repository address, either http or ssh]:REMOTE:_default' \
'-t+[Target destination, repository name by default]:TARGET:_files' \
'--target=[Target destination, repository name by default]:TARGET:_files' \
'*-p+[A list of comma-separated profiles to activate]' \
'*--profiles=[A list of comma-separated profiles to activate]' \
'-f[Force symlink creation even if the target already exists, a backup will be created]' \
'--force[Force symlink creation even if the target already exists, a backup will be created]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(link)
_arguments "${_arguments_options[@]}" : \
'*-p+[A list of comma-separated profiles to activate]' \
'*--profiles=[A list of comma-separated profiles to activate]' \
'-f[Force symlink creation even if the target already exists, a backup will be created]' \
'--force[Force symlink creation even if the target already exists, a backup will be created]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(unlink)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(watch)
_arguments "${_arguments_options[@]}" : \
'*-p+[A list of comma-separated profiles to activate]' \
'*--profiles=[A list of comma-separated profiles to activate]' \
'-f[Force symlink creation even if the target already exists, a backup will be created]' \
'--force[Force symlink creation even if the target already exists, a backup will be created]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(add-secret)
_arguments "${_arguments_options[@]}" : \
'-k+[Key of the secret variable to create]:KEY:_default' \
'--key=[Key of the secret variable to create]:KEY:_default' \
'-v+[]:VALUE:_default' \
'--value=[]:VALUE:_default' \
'-f+[Path of the var file to modify]:FILE:_default' \
'--file=[Path of the var file to modify]:FILE:_default' \
'-a[Get the secret value from stdin]' \
'--ask[Get the secret value from stdin]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(get)
_arguments "${_arguments_options[@]}" : \
'-n[]' \
'--no-color[]' \
'-h[Print help]' \
'--help[Print help]' \
':value:(dots prehooks posthooks path profiles vars secrets)' \
'*::profiles:()' \
&& ret=0
;;
(generate-completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':type -- Type of completions to generate:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_bombadil__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:bombadil-help-command-$line[1]:"
        case $line[1] in
            (install)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(clone)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(link)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(unlink)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(watch)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(add-secret)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(get)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(generate-completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_bombadil_commands] )) ||
_bombadil_commands() {
    local commands; commands=(
'install:Link a given dotfile directory settings to "XDG_CONFIG_DIR/bombadil.toml"' \
'clone:Install dotfiles from a remote git repository to a target folder' \
'link:Symlink a copy of your dotfiles and inject variables according to bombadil.toml settings' \
'unlink:Remove all symlinks defined in your bombadil.toml' \
'watch:Watch dotfiles and automatically run link on changes' \
'add-secret:Add a secret var to bombadil environment' \
'get:Get metadata about dots, hooks, path, profiles, or vars' \
'generate-completions:Generate shell completions Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'bombadil commands' commands "$@"
}
(( $+functions[_bombadil__add-secret_commands] )) ||
_bombadil__add-secret_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil add-secret commands' commands "$@"
}
(( $+functions[_bombadil__clone_commands] )) ||
_bombadil__clone_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil clone commands' commands "$@"
}
(( $+functions[_bombadil__generate-completions_commands] )) ||
_bombadil__generate-completions_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil generate-completions commands' commands "$@"
}
(( $+functions[_bombadil__get_commands] )) ||
_bombadil__get_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil get commands' commands "$@"
}
(( $+functions[_bombadil__help_commands] )) ||
_bombadil__help_commands() {
    local commands; commands=(
'install:Link a given dotfile directory settings to "XDG_CONFIG_DIR/bombadil.toml"' \
'clone:Install dotfiles from a remote git repository to a target folder' \
'link:Symlink a copy of your dotfiles and inject variables according to bombadil.toml settings' \
'unlink:Remove all symlinks defined in your bombadil.toml' \
'watch:Watch dotfiles and automatically run link on changes' \
'add-secret:Add a secret var to bombadil environment' \
'get:Get metadata about dots, hooks, path, profiles, or vars' \
'generate-completions:Generate shell completions Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'bombadil help commands' commands "$@"
}
(( $+functions[_bombadil__help__add-secret_commands] )) ||
_bombadil__help__add-secret_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help add-secret commands' commands "$@"
}
(( $+functions[_bombadil__help__clone_commands] )) ||
_bombadil__help__clone_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help clone commands' commands "$@"
}
(( $+functions[_bombadil__help__generate-completions_commands] )) ||
_bombadil__help__generate-completions_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help generate-completions commands' commands "$@"
}
(( $+functions[_bombadil__help__get_commands] )) ||
_bombadil__help__get_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help get commands' commands "$@"
}
(( $+functions[_bombadil__help__help_commands] )) ||
_bombadil__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help help commands' commands "$@"
}
(( $+functions[_bombadil__help__install_commands] )) ||
_bombadil__help__install_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help install commands' commands "$@"
}
(( $+functions[_bombadil__help__link_commands] )) ||
_bombadil__help__link_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help link commands' commands "$@"
}
(( $+functions[_bombadil__help__unlink_commands] )) ||
_bombadil__help__unlink_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help unlink commands' commands "$@"
}
(( $+functions[_bombadil__help__watch_commands] )) ||
_bombadil__help__watch_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil help watch commands' commands "$@"
}
(( $+functions[_bombadil__install_commands] )) ||
_bombadil__install_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil install commands' commands "$@"
}
(( $+functions[_bombadil__link_commands] )) ||
_bombadil__link_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil link commands' commands "$@"
}
(( $+functions[_bombadil__unlink_commands] )) ||
_bombadil__unlink_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil unlink commands' commands "$@"
}
(( $+functions[_bombadil__watch_commands] )) ||
_bombadil__watch_commands() {
    local commands; commands=()
    _describe -t commands 'bombadil watch commands' commands "$@"
}

if [ "$funcstack[1]" = "_bombadil" ]; then
    _bombadil "$@"
else
    compdef _bombadil bombadil
fi

