#compdef kbs2

autoload -U is-at-least

_kbs2() {
    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+[use the specified config directory]:DIR:_files -/' \
'--config-dir=[use the specified config directory]:DIR:_files -/' \
'--completions=[emit shell tab completions]:SHELL:(bash elvish fish powershell zsh)' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_kbs2_commands" \
"*::: :->kbs2" \
&& ret=0
    case $state in
    (kbs2)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-command-$line[1]:"
        case $line[1] in
            (agent)
_arguments "${_arguments_options[@]}" : \
'-F[run the agent in the foreground]' \
'--foreground[run the agent in the foreground]' \
'-h[Print help]' \
'--help[Print help]' \
":: :_kbs2__agent_commands" \
"*::: :->agent" \
&& ret=0

    case $state in
    (agent)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-agent-command-$line[1]:"
        case $line[1] in
            (flush)
_arguments "${_arguments_options[@]}" : \
'-q[quit the agent after flushing]' \
'--quit[quit the agent after flushing]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(query)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(unwrap)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_kbs2__agent__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-agent-help-command-$line[1]:"
        case $line[1] in
            (flush)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(query)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(unwrap)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(init)
_arguments "${_arguments_options[@]}" : \
'-s+[the directory to store encrypted kbs2 records in]:DIR:_files -/' \
'--store-dir=[the directory to store encrypted kbs2 records in]:DIR:_files -/' \
'-f[overwrite the config and keyfile, if already present]' \
'--force[overwrite the config and keyfile, if already present]' \
'--insecure-not-wrapped[don'\''t wrap the keypair with a master password]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(new)
_arguments "${_arguments_options[@]}" : \
'-k+[the kind of record to create]: :(login environment unstructured)' \
'--kind=[the kind of record to create]: :(login environment unstructured)' \
'-G+[use the given generator to generate sensitive fields]: :_default' \
'--generator=[use the given generator to generate sensitive fields]: :_default' \
'-f[overwrite, if already present]' \
'--force[overwrite, if already present]' \
'-t[read fields in a terse format, even when connected to a tty]' \
'--terse[read fields in a terse format, even when connected to a tty]' \
'-h[Print help]' \
'--help[Print help]' \
':label -- the record'\''s label:_default' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'-k+[list only records of this kind]: :(login environment unstructured)' \
'--kind=[list only records of this kind]: :(login environment unstructured)' \
'-d[print (non-field) details for each record]' \
'--details[print (non-field) details for each record]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(rm)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::label -- the labels of the records to remove:_default' \
&& ret=0
;;
(rename)
_arguments "${_arguments_options[@]}" : \
'-f[overwrite, if already present]' \
'--force[overwrite, if already present]' \
'-h[Print help]' \
'--help[Print help]' \
':old-label -- the record'\''s current label:_default' \
':new-label -- the new record label:_default' \
&& ret=0
;;
(dump)
_arguments "${_arguments_options[@]}" : \
'-j[dump in JSON format (JSONL when multiple)]' \
'--json[dump in JSON format (JSONL when multiple)]' \
'-h[Print help]' \
'--help[Print help]' \
'*::label -- the labels of the records to dump:_default' \
&& ret=0
;;
(pass)
_arguments "${_arguments_options[@]}" : \
'-c[copy the password to the clipboard]' \
'--clipboard[copy the password to the clipboard]' \
'-h[Print help]' \
'--help[Print help]' \
':label -- the record'\''s label:_default' \
&& ret=0
;;
(env)
_arguments "${_arguments_options[@]}" : \
'-v[print only the environment variable value, not the variable name]' \
'--value-only[print only the environment variable value, not the variable name]' \
'-n[print only VAR=val without \`export\`]' \
'--no-export[print only VAR=val without \`export\`]' \
'-h[Print help]' \
'--help[Print help]' \
':label -- the record'\''s label:_default' \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
'-p+[don'\''t update the record'\''s timestamp]: :_default' \
'--preserve-timestamp=[don'\''t update the record'\''s timestamp]: :_default' \
'-h[Print help]' \
'--help[Print help]' \
':label -- the record'\''s label:_default' \
&& ret=0
;;
(generate)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'::generator -- the generator to use:_default' \
&& ret=0
;;
(rewrap)
_arguments "${_arguments_options[@]}" : \
'-n[don'\''t make a backup of the old wrapped key]' \
'--no-backup[don'\''t make a backup of the old wrapped key]' \
'-f[overwrite a previous backup, if one exists]' \
'--force[overwrite a previous backup, if one exists]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(rekey)
_arguments "${_arguments_options[@]}" : \
'-n[don'\''t make a backup of the old wrapped key, config, or store]' \
'--no-backup[don'\''t make a backup of the old wrapped key, config, or store]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(config)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
":: :_kbs2__config_commands" \
"*::: :->config" \
&& ret=0

    case $state in
    (config)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-config-command-$line[1]:"
        case $line[1] in
            (dump)
_arguments "${_arguments_options[@]}" : \
'-p[pretty-print the JSON]' \
'--pretty[pretty-print the JSON]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_kbs2__config__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-config-help-command-$line[1]:"
        case $line[1] in
            (dump)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_kbs2__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-help-command-$line[1]:"
        case $line[1] in
            (agent)
_arguments "${_arguments_options[@]}" : \
":: :_kbs2__help__agent_commands" \
"*::: :->agent" \
&& ret=0

    case $state in
    (agent)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kbs2-help-agent-command-$line[1]:"
        case $line[1] in
            (flush)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(query)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(unwrap)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
(init)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(new)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rm)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rename)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(dump)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(pass)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(env)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(generate)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rewrap)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rekey)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(config)
_arguments "${_arguments_options[@]}" : \
":: :_kbs2__help__config_commands" \
"*::: :->config" \
&& ret=0

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

(( $+functions[_kbs2_commands] )) ||
_kbs2_commands() {
    local commands; commands=(
'agent:run the kbs2 authentication agent' \
'init:initialize kbs2 with a new config and keypair' \
'new:create a new record' \
'list:list records' \
'rm:remove one or more records' \
'rename:rename a record' \
'dump:dump one or more records' \
'pass:get the password in a login record' \
'env:get an environment record' \
'edit:modify a record with a text editor' \
'generate:generate secret values using a generator' \
'rewrap:change the master password on a wrapped key' \
'rekey:re-encrypt the entire store with a new keypair and master password' \
'config:interact with kbs2'\''s configuration file' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 commands' commands "$@"
}
(( $+functions[_kbs2__agent_commands] )) ||
_kbs2__agent_commands() {
    local commands; commands=(
'flush:remove all unwrapped keys from the running agent' \
'query:ask the current agent whether it has the current config'\''s key' \
'unwrap:unwrap the current config'\''s key in the running agent' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 agent commands' commands "$@"
}
(( $+functions[_kbs2__agent__flush_commands] )) ||
_kbs2__agent__flush_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent flush commands' commands "$@"
}
(( $+functions[_kbs2__agent__help_commands] )) ||
_kbs2__agent__help_commands() {
    local commands; commands=(
'flush:remove all unwrapped keys from the running agent' \
'query:ask the current agent whether it has the current config'\''s key' \
'unwrap:unwrap the current config'\''s key in the running agent' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 agent help commands' commands "$@"
}
(( $+functions[_kbs2__agent__help__flush_commands] )) ||
_kbs2__agent__help__flush_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent help flush commands' commands "$@"
}
(( $+functions[_kbs2__agent__help__help_commands] )) ||
_kbs2__agent__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent help help commands' commands "$@"
}
(( $+functions[_kbs2__agent__help__query_commands] )) ||
_kbs2__agent__help__query_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent help query commands' commands "$@"
}
(( $+functions[_kbs2__agent__help__unwrap_commands] )) ||
_kbs2__agent__help__unwrap_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent help unwrap commands' commands "$@"
}
(( $+functions[_kbs2__agent__query_commands] )) ||
_kbs2__agent__query_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent query commands' commands "$@"
}
(( $+functions[_kbs2__agent__unwrap_commands] )) ||
_kbs2__agent__unwrap_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 agent unwrap commands' commands "$@"
}
(( $+functions[_kbs2__config_commands] )) ||
_kbs2__config_commands() {
    local commands; commands=(
'dump:dump the active configuration file as JSON' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 config commands' commands "$@"
}
(( $+functions[_kbs2__config__dump_commands] )) ||
_kbs2__config__dump_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 config dump commands' commands "$@"
}
(( $+functions[_kbs2__config__help_commands] )) ||
_kbs2__config__help_commands() {
    local commands; commands=(
'dump:dump the active configuration file as JSON' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 config help commands' commands "$@"
}
(( $+functions[_kbs2__config__help__dump_commands] )) ||
_kbs2__config__help__dump_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 config help dump commands' commands "$@"
}
(( $+functions[_kbs2__config__help__help_commands] )) ||
_kbs2__config__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 config help help commands' commands "$@"
}
(( $+functions[_kbs2__dump_commands] )) ||
_kbs2__dump_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 dump commands' commands "$@"
}
(( $+functions[_kbs2__edit_commands] )) ||
_kbs2__edit_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 edit commands' commands "$@"
}
(( $+functions[_kbs2__env_commands] )) ||
_kbs2__env_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 env commands' commands "$@"
}
(( $+functions[_kbs2__generate_commands] )) ||
_kbs2__generate_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 generate commands' commands "$@"
}
(( $+functions[_kbs2__help_commands] )) ||
_kbs2__help_commands() {
    local commands; commands=(
'agent:run the kbs2 authentication agent' \
'init:initialize kbs2 with a new config and keypair' \
'new:create a new record' \
'list:list records' \
'rm:remove one or more records' \
'rename:rename a record' \
'dump:dump one or more records' \
'pass:get the password in a login record' \
'env:get an environment record' \
'edit:modify a record with a text editor' \
'generate:generate secret values using a generator' \
'rewrap:change the master password on a wrapped key' \
'rekey:re-encrypt the entire store with a new keypair and master password' \
'config:interact with kbs2'\''s configuration file' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kbs2 help commands' commands "$@"
}
(( $+functions[_kbs2__help__agent_commands] )) ||
_kbs2__help__agent_commands() {
    local commands; commands=(
'flush:remove all unwrapped keys from the running agent' \
'query:ask the current agent whether it has the current config'\''s key' \
'unwrap:unwrap the current config'\''s key in the running agent' \
    )
    _describe -t commands 'kbs2 help agent commands' commands "$@"
}
(( $+functions[_kbs2__help__agent__flush_commands] )) ||
_kbs2__help__agent__flush_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help agent flush commands' commands "$@"
}
(( $+functions[_kbs2__help__agent__query_commands] )) ||
_kbs2__help__agent__query_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help agent query commands' commands "$@"
}
(( $+functions[_kbs2__help__agent__unwrap_commands] )) ||
_kbs2__help__agent__unwrap_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help agent unwrap commands' commands "$@"
}
(( $+functions[_kbs2__help__config_commands] )) ||
_kbs2__help__config_commands() {
    local commands; commands=(
'dump:dump the active configuration file as JSON' \
    )
    _describe -t commands 'kbs2 help config commands' commands "$@"
}
(( $+functions[_kbs2__help__config__dump_commands] )) ||
_kbs2__help__config__dump_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help config dump commands' commands "$@"
}
(( $+functions[_kbs2__help__dump_commands] )) ||
_kbs2__help__dump_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help dump commands' commands "$@"
}
(( $+functions[_kbs2__help__edit_commands] )) ||
_kbs2__help__edit_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help edit commands' commands "$@"
}
(( $+functions[_kbs2__help__env_commands] )) ||
_kbs2__help__env_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help env commands' commands "$@"
}
(( $+functions[_kbs2__help__generate_commands] )) ||
_kbs2__help__generate_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help generate commands' commands "$@"
}
(( $+functions[_kbs2__help__help_commands] )) ||
_kbs2__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help help commands' commands "$@"
}
(( $+functions[_kbs2__help__init_commands] )) ||
_kbs2__help__init_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help init commands' commands "$@"
}
(( $+functions[_kbs2__help__list_commands] )) ||
_kbs2__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help list commands' commands "$@"
}
(( $+functions[_kbs2__help__new_commands] )) ||
_kbs2__help__new_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help new commands' commands "$@"
}
(( $+functions[_kbs2__help__pass_commands] )) ||
_kbs2__help__pass_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help pass commands' commands "$@"
}
(( $+functions[_kbs2__help__rekey_commands] )) ||
_kbs2__help__rekey_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help rekey commands' commands "$@"
}
(( $+functions[_kbs2__help__rename_commands] )) ||
_kbs2__help__rename_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help rename commands' commands "$@"
}
(( $+functions[_kbs2__help__rewrap_commands] )) ||
_kbs2__help__rewrap_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help rewrap commands' commands "$@"
}
(( $+functions[_kbs2__help__rm_commands] )) ||
_kbs2__help__rm_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 help rm commands' commands "$@"
}
(( $+functions[_kbs2__init_commands] )) ||
_kbs2__init_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 init commands' commands "$@"
}
(( $+functions[_kbs2__list_commands] )) ||
_kbs2__list_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 list commands' commands "$@"
}
(( $+functions[_kbs2__new_commands] )) ||
_kbs2__new_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 new commands' commands "$@"
}
(( $+functions[_kbs2__pass_commands] )) ||
_kbs2__pass_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 pass commands' commands "$@"
}
(( $+functions[_kbs2__rekey_commands] )) ||
_kbs2__rekey_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 rekey commands' commands "$@"
}
(( $+functions[_kbs2__rename_commands] )) ||
_kbs2__rename_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 rename commands' commands "$@"
}
(( $+functions[_kbs2__rewrap_commands] )) ||
_kbs2__rewrap_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 rewrap commands' commands "$@"
}
(( $+functions[_kbs2__rm_commands] )) ||
_kbs2__rm_commands() {
    local commands; commands=()
    _describe -t commands 'kbs2 rm commands' commands "$@"
}

if [ "$funcstack[1]" = "_kbs2" ]; then
    _kbs2 "$@"
else
    compdef _kbs2 kbs2
fi
