#compdef remuda

autoload -U is-at-least

_remuda() {
    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[@]}" : \
'(--check-update)--update[Replace this binary with the latest release]' \
'--check-update[Only report whether a newer release exists]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_remuda_commands" \
"*::: :->remuda" \
&& ret=0
    case $state in
    (remuda)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:remuda-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'--json[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(import)
_arguments "${_arguments_options[@]}" : \
'-p+[]:PROVIDER:(claude codex cursor glm grok kimi opencode)' \
'--provider=[]:PROVIDER:(claude codex cursor glm grok kimi opencode)' \
'--force[Replace a stored credential of the same name]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(login)
_arguments "${_arguments_options[@]}" : \
'-p+[]:PROVIDER:(claude codex cursor glm grok kimi opencode)' \
'--provider=[]:PROVIDER:(claude codex cursor glm grok kimi opencode)' \
'--force[]' \
'--no-browser[Print the URL instead of opening it]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(use)
_arguments "${_arguments_options[@]}" : \
'--discard[Switch even when the live login is not in the store, dropping it]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(refresh)
_arguments "${_arguments_options[@]}" : \
'--within=[Refresh anything expiring within this many minutes]:WITHIN:_default' \
'--force[Refresh even when the access token is still fresh]' \
'--scheduled[Run as the refresh timer\: stop where the directories differ from the ones the last interactive command used]' \
'-h[Print help]' \
'--help[Print help]' \
'::name:_default' \
&& ret=0
;;
(label)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
'::text:_default' \
&& ret=0
;;
(env)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(rename)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
':new_name:_default' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(auto)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
'*::args:_default' \
&& ret=0
;;
(pin)
_arguments "${_arguments_options[@]}" : \
'()--remove=[Unpin this CLI from ./.remuda.toml instead]:CLI:_default' \
'(--remove)--allow[Trust the nearest .remuda.toml as it is now\: one written by anything but \`remuda pin\`, a clone'\''s for one, is not read until allowed]' \
'-h[Print help]' \
'--help[Print help]' \
'::name:_default' \
&& ret=0
;;
(shell-init)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:_default' \
&& ret=0
;;
(log)
_arguments "${_arguments_options[@]}" : \
'-n+[How many of the latest events to show]:LINES:_default' \
'--lines=[How many of the latest events to show]:LINES:_default' \
'--json[Print the events as JSON]' \
'-h[Print help]' \
'--help[Print help]' \
'::name -- A provider (claude), a login (claude/work) or a bare name:_default' \
&& ret=0
;;
(serve)
_arguments "${_arguments_options[@]}" : \
'--port=[]:PORT:_default' \
'--no-browser[Print the URL instead of opening it]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(open)
_arguments "${_arguments_options[@]}" : \
'--no-browser[Print the URL instead of opening it]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(sync-units)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_remuda__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:remuda-help-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(import)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(login)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(use)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(refresh)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(label)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(env)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rename)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(auto)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(pin)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(shell-init)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(log)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(serve)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(open)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(sync-units)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_remuda_commands] )) ||
_remuda_commands() {
    local commands; commands=(
'list:List stored credentials and which one each CLI is using' \
'import:Store the login a CLI is signed into right now' \
'login:Sign a new account in through the browser and store it, without touching the CLI' \
'use:Make a stored credential the one its CLI uses. NAME or PROVIDER/NAME' \
'refresh:Refresh the tokens of the inactive credentials that are close to expiring' \
'label:Set the label shown beside a credential, or clear it. NAME or PROVIDER/NAME' \
'env:Print the shell line that makes a CLI reading its key from the environment use a stored one\: \`eval "\$(remuda env glm/work)"\`' \
'rename:Rename a stored credential. NAME or PROVIDER/NAME' \
'remove:Delete a stored credential. NAME or PROVIDER/NAME' \
'auto:Say which login auto mode puts each CLI on now, and why, without switching' \
'run:Start a CLI on a stored login without switching the one every other session uses\: NAME, PROVIDER/NAME, or a provider alone for the login \`.remuda.toml\` pins here, else the one it uses now. Anything after \`--\` goes to the CLI' \
'pin:Pin a login for this directory and below in ./.remuda.toml, so \`remuda run <cli>\` starts it there; with no NAME, show the pins in force' \
'shell-init:Print shell functions that start \`claude\` and \`codex\` through \`remuda run\`, for the login pinned where they start\: \`eval "\$(remuda shell-init zsh)"\`' \
'log:Show what remuda did\: switches and who made them, refreshes, auto mode, keep-warm, the proxy. PROVIDER, NAME or PROVIDER/NAME narrows it' \
'serve:Serve a local page to list, switch and sign in credentials from the browser' \
'open:Open the page a running \`remuda serve\` shows, starting remuda-serve.service when it is installed' \
'completions:Print a completion script for a shell' \
'sync-units:Run by \`--update\` as the new binary\: bring the installed units up to date' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'remuda commands' commands "$@"
}
(( $+functions[_remuda__subcmd__auto_commands] )) ||
_remuda__subcmd__auto_commands() {
    local commands; commands=()
    _describe -t commands 'remuda auto commands' commands "$@"
}
(( $+functions[_remuda__subcmd__completions_commands] )) ||
_remuda__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'remuda completions commands' commands "$@"
}
(( $+functions[_remuda__subcmd__env_commands] )) ||
_remuda__subcmd__env_commands() {
    local commands; commands=()
    _describe -t commands 'remuda env commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help_commands] )) ||
_remuda__subcmd__help_commands() {
    local commands; commands=(
'list:List stored credentials and which one each CLI is using' \
'import:Store the login a CLI is signed into right now' \
'login:Sign a new account in through the browser and store it, without touching the CLI' \
'use:Make a stored credential the one its CLI uses. NAME or PROVIDER/NAME' \
'refresh:Refresh the tokens of the inactive credentials that are close to expiring' \
'label:Set the label shown beside a credential, or clear it. NAME or PROVIDER/NAME' \
'env:Print the shell line that makes a CLI reading its key from the environment use a stored one\: \`eval "\$(remuda env glm/work)"\`' \
'rename:Rename a stored credential. NAME or PROVIDER/NAME' \
'remove:Delete a stored credential. NAME or PROVIDER/NAME' \
'auto:Say which login auto mode puts each CLI on now, and why, without switching' \
'run:Start a CLI on a stored login without switching the one every other session uses\: NAME, PROVIDER/NAME, or a provider alone for the login \`.remuda.toml\` pins here, else the one it uses now. Anything after \`--\` goes to the CLI' \
'pin:Pin a login for this directory and below in ./.remuda.toml, so \`remuda run <cli>\` starts it there; with no NAME, show the pins in force' \
'shell-init:Print shell functions that start \`claude\` and \`codex\` through \`remuda run\`, for the login pinned where they start\: \`eval "\$(remuda shell-init zsh)"\`' \
'log:Show what remuda did\: switches and who made them, refreshes, auto mode, keep-warm, the proxy. PROVIDER, NAME or PROVIDER/NAME narrows it' \
'serve:Serve a local page to list, switch and sign in credentials from the browser' \
'open:Open the page a running \`remuda serve\` shows, starting remuda-serve.service when it is installed' \
'completions:Print a completion script for a shell' \
'sync-units:Run by \`--update\` as the new binary\: bring the installed units up to date' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'remuda help commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__auto_commands] )) ||
_remuda__subcmd__help__subcmd__auto_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help auto commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__completions_commands] )) ||
_remuda__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help completions commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__env_commands] )) ||
_remuda__subcmd__help__subcmd__env_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help env commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__help_commands] )) ||
_remuda__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help help commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__import_commands] )) ||
_remuda__subcmd__help__subcmd__import_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help import commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__label_commands] )) ||
_remuda__subcmd__help__subcmd__label_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help label commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__list_commands] )) ||
_remuda__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help list commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__log_commands] )) ||
_remuda__subcmd__help__subcmd__log_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help log commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__login_commands] )) ||
_remuda__subcmd__help__subcmd__login_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help login commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__open_commands] )) ||
_remuda__subcmd__help__subcmd__open_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help open commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__pin_commands] )) ||
_remuda__subcmd__help__subcmd__pin_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help pin commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__refresh_commands] )) ||
_remuda__subcmd__help__subcmd__refresh_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help refresh commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__remove_commands] )) ||
_remuda__subcmd__help__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help remove commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__rename_commands] )) ||
_remuda__subcmd__help__subcmd__rename_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help rename commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__run_commands] )) ||
_remuda__subcmd__help__subcmd__run_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help run commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__serve_commands] )) ||
_remuda__subcmd__help__subcmd__serve_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help serve commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__shell-init_commands] )) ||
_remuda__subcmd__help__subcmd__shell-init_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help shell-init commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__sync-units_commands] )) ||
_remuda__subcmd__help__subcmd__sync-units_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help sync-units commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help__subcmd__use_commands] )) ||
_remuda__subcmd__help__subcmd__use_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help use commands' commands "$@"
}
(( $+functions[_remuda__subcmd__import_commands] )) ||
_remuda__subcmd__import_commands() {
    local commands; commands=()
    _describe -t commands 'remuda import commands' commands "$@"
}
(( $+functions[_remuda__subcmd__label_commands] )) ||
_remuda__subcmd__label_commands() {
    local commands; commands=()
    _describe -t commands 'remuda label commands' commands "$@"
}
(( $+functions[_remuda__subcmd__list_commands] )) ||
_remuda__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'remuda list commands' commands "$@"
}
(( $+functions[_remuda__subcmd__log_commands] )) ||
_remuda__subcmd__log_commands() {
    local commands; commands=()
    _describe -t commands 'remuda log commands' commands "$@"
}
(( $+functions[_remuda__subcmd__login_commands] )) ||
_remuda__subcmd__login_commands() {
    local commands; commands=()
    _describe -t commands 'remuda login commands' commands "$@"
}
(( $+functions[_remuda__subcmd__open_commands] )) ||
_remuda__subcmd__open_commands() {
    local commands; commands=()
    _describe -t commands 'remuda open commands' commands "$@"
}
(( $+functions[_remuda__subcmd__pin_commands] )) ||
_remuda__subcmd__pin_commands() {
    local commands; commands=()
    _describe -t commands 'remuda pin commands' commands "$@"
}
(( $+functions[_remuda__subcmd__refresh_commands] )) ||
_remuda__subcmd__refresh_commands() {
    local commands; commands=()
    _describe -t commands 'remuda refresh commands' commands "$@"
}
(( $+functions[_remuda__subcmd__remove_commands] )) ||
_remuda__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'remuda remove commands' commands "$@"
}
(( $+functions[_remuda__subcmd__rename_commands] )) ||
_remuda__subcmd__rename_commands() {
    local commands; commands=()
    _describe -t commands 'remuda rename commands' commands "$@"
}
(( $+functions[_remuda__subcmd__run_commands] )) ||
_remuda__subcmd__run_commands() {
    local commands; commands=()
    _describe -t commands 'remuda run commands' commands "$@"
}
(( $+functions[_remuda__subcmd__serve_commands] )) ||
_remuda__subcmd__serve_commands() {
    local commands; commands=()
    _describe -t commands 'remuda serve commands' commands "$@"
}
(( $+functions[_remuda__subcmd__shell-init_commands] )) ||
_remuda__subcmd__shell-init_commands() {
    local commands; commands=()
    _describe -t commands 'remuda shell-init commands' commands "$@"
}
(( $+functions[_remuda__subcmd__sync-units_commands] )) ||
_remuda__subcmd__sync-units_commands() {
    local commands; commands=()
    _describe -t commands 'remuda sync-units commands' commands "$@"
}
(( $+functions[_remuda__subcmd__use_commands] )) ||
_remuda__subcmd__use_commands() {
    local commands; commands=()
    _describe -t commands 'remuda use commands' commands "$@"
}

if [ "$funcstack[1]" = "_remuda" ]; then
    _remuda "$@"
else
    compdef _remuda remuda
fi
