#compdef pibtool

autoload -U is-at-least

_pibtool() {
    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]' \
":: :_pibtool_commands" \
"*::: :->pibtool" \
&& ret=0
    case $state in
    (pibtool)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:pibtool-command-$line[1]:"
        case $line[1] in
            (fetch-documents)
_arguments "${_arguments_options[@]}" : \
'--only-recent-years=[Set the number of recent years which should be checked for new documents]:ONLY_RECENT_YEARS:_default' \
'--force-download[Force a (re-)download, even if the file is already known to \`pibtool\`]' \
'--recursive[Recurse into subdirectories and download for all authorities found there]' \
'*-v[Switch to a more verbose mode. By default, only \`info\`, \`warn\` and \`error\` log levels are printed. Given once, \`debug\` log level is turned on. Given twice or more, \`trace\` log level is turned on as well]' \
'*--verbose[Switch to a more verbose mode. By default, only \`info\`, \`warn\` and \`error\` log levels are printed. Given once, \`debug\` log level is turned on. Given twice or more, \`trace\` log level is turned on as well]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(fetch-borders)
_arguments "${_arguments_options[@]}" : \
'--geojson-converter=[Convert the download OSM JSON file to GeoJson with this command if present]:GEOJSON_CONVERTER:_default' \
'--simplify-tolerance=[Simplify the downloaded borders using the Douglas-Peucker algorithm with the given tolerance]:SIMPLIFY_TOLERANCE:_default' \
'--force-download[Force a (re-)download,  even if the file is already present]' \
'--recursive[Recurse into subdirectories and download for all authorities found there]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(generate-website-data)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(generate-shell-completion)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_pibtool__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:pibtool-help-command-$line[1]:"
        case $line[1] in
            (fetch-documents)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(fetch-borders)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(generate-website-data)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(generate-shell-completion)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_pibtool_commands] )) ||
_pibtool_commands() {
    local commands; commands=(
'fetch-documents:Fetch documents from one or multiple authorities' \
'fetch-borders:Fetch the borders from the OpenStreetMap overpass API' \
'check:Check that the \`pib.json\` definition files in the current directory are correct' \
'generate-website-data:Generate website data' \
'generate-shell-completion:Generate shell comletion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'pibtool commands' commands "$@"
}
(( $+functions[_pibtool__check_commands] )) ||
_pibtool__check_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool check commands' commands "$@"
}
(( $+functions[_pibtool__fetch-borders_commands] )) ||
_pibtool__fetch-borders_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool fetch-borders commands' commands "$@"
}
(( $+functions[_pibtool__fetch-documents_commands] )) ||
_pibtool__fetch-documents_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool fetch-documents commands' commands "$@"
}
(( $+functions[_pibtool__generate-shell-completion_commands] )) ||
_pibtool__generate-shell-completion_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool generate-shell-completion commands' commands "$@"
}
(( $+functions[_pibtool__generate-website-data_commands] )) ||
_pibtool__generate-website-data_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool generate-website-data commands' commands "$@"
}
(( $+functions[_pibtool__help_commands] )) ||
_pibtool__help_commands() {
    local commands; commands=(
'fetch-documents:Fetch documents from one or multiple authorities' \
'fetch-borders:Fetch the borders from the OpenStreetMap overpass API' \
'check:Check that the \`pib.json\` definition files in the current directory are correct' \
'generate-website-data:Generate website data' \
'generate-shell-completion:Generate shell comletion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'pibtool help commands' commands "$@"
}
(( $+functions[_pibtool__help__check_commands] )) ||
_pibtool__help__check_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help check commands' commands "$@"
}
(( $+functions[_pibtool__help__fetch-borders_commands] )) ||
_pibtool__help__fetch-borders_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help fetch-borders commands' commands "$@"
}
(( $+functions[_pibtool__help__fetch-documents_commands] )) ||
_pibtool__help__fetch-documents_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help fetch-documents commands' commands "$@"
}
(( $+functions[_pibtool__help__generate-shell-completion_commands] )) ||
_pibtool__help__generate-shell-completion_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help generate-shell-completion commands' commands "$@"
}
(( $+functions[_pibtool__help__generate-website-data_commands] )) ||
_pibtool__help__generate-website-data_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help generate-website-data commands' commands "$@"
}
(( $+functions[_pibtool__help__help_commands] )) ||
_pibtool__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'pibtool help help commands' commands "$@"
}

if [ "$funcstack[1]" = "_pibtool" ]; then
    _pibtool "$@"
else
    compdef _pibtool pibtool
fi
