#compdef infat

autoload -U is-at-least

_infat() {
    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[@]}" : \
'-c+[Path to the configuration file]:PATH:_files' \
'--config=[Path to the configuration file]:PATH:_files' \
'-v[Enable verbose logging]' \
'--verbose[Enable verbose logging]' \
'-q[Suppress all output except errors]' \
'--quiet[Suppress all output except errors]' \
'--robust[Continue processing on errors when possible]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_infat_commands" \
"*::: :->infat-cli" \
&& ret=0
    case $state in
    (infat-cli)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:infat-command-$line[1]:"
        case $line[1] in
            (info)
_arguments "${_arguments_options[@]}" : \
'(--ext --scheme --type)--app=[Show information for a specific application]:APP:_default' \
'(--app --scheme --type)--ext=[Show information for a file extension]:EXT:_default' \
'(--app --ext --type)--scheme=[Show information for a URL scheme]:SCHEME:_default' \
'(--app --ext --scheme)--type=[Show information for a file type]:TYPE:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(set)
_arguments "${_arguments_options[@]}" : \
'(--scheme --type)--ext=[File extension to associate (without the dot)]:EXT:_default' \
'(--ext --type)--scheme=[URL scheme to associate]:SCHEME:_default' \
'(--ext --scheme)--type=[File type to associate]:TYPE:_default' \
'-h[Print help]' \
'--help[Print help]' \
':app_name -- Application name to set as default:_default' \
&& ret=0
;;
(init)
_arguments "${_arguments_options[@]}" : \
'-o+[Output configuration file path (defaults to XDG config location)]:PATH:_files' \
'--output=[Output configuration file path (defaults to XDG config location)]:PATH:_files' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_infat__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:infat-help-command-$line[1]:"
        case $line[1] in
            (info)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(set)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(init)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_infat_commands] )) ||
_infat_commands() {
    local commands; commands=(
'info:Show file association information' \
'set:Set default application for file extension, URL scheme, or file type' \
'init:Initialize configuration from current Launch Services settings' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'infat commands' commands "$@"
}
(( $+functions[_infat__help_commands] )) ||
_infat__help_commands() {
    local commands; commands=(
'info:Show file association information' \
'set:Set default application for file extension, URL scheme, or file type' \
'init:Initialize configuration from current Launch Services settings' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'infat help commands' commands "$@"
}
(( $+functions[_infat__help__help_commands] )) ||
_infat__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'infat help help commands' commands "$@"
}
(( $+functions[_infat__help__info_commands] )) ||
_infat__help__info_commands() {
    local commands; commands=()
    _describe -t commands 'infat help info commands' commands "$@"
}
(( $+functions[_infat__help__init_commands] )) ||
_infat__help__init_commands() {
    local commands; commands=()
    _describe -t commands 'infat help init commands' commands "$@"
}
(( $+functions[_infat__help__set_commands] )) ||
_infat__help__set_commands() {
    local commands; commands=()
    _describe -t commands 'infat help set commands' commands "$@"
}
(( $+functions[_infat__info_commands] )) ||
_infat__info_commands() {
    local commands; commands=()
    _describe -t commands 'infat info commands' commands "$@"
}
(( $+functions[_infat__init_commands] )) ||
_infat__init_commands() {
    local commands; commands=()
    _describe -t commands 'infat init commands' commands "$@"
}
(( $+functions[_infat__set_commands] )) ||
_infat__set_commands() {
    local commands; commands=()
    _describe -t commands 'infat set commands' commands "$@"
}

if [ "$funcstack[1]" = "_infat" ]; then
    _infat "$@"
else
    compdef _infat infat
fi
