#compdef rgb-cli

autoload -U is-at-least

_rgb-cli() {
    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[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
":: :_rgb-cli_commands" \
"*::: :->rgb-cli" \
&& ret=0
    case $state in
    (rgb-cli)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rgb-cli-command-$line[1]:"
        case $line[1] in
            (register)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'--force[Force importing of valid contract containing non-mined transactions]' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':contract -- Contract source in Bech32m encoding (starting with `rgbc1...`):' \
&& ret=0
;;
(contracts)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
&& ret=0
;;
(state)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':contract-id -- Contract id to read state:' \
&& ret=0
;;
(contract)
_arguments "${_arguments_options[@]}" \
'*-t+[]:NODE_TYPES: ' \
'*--node-type=[]:NODE_TYPES: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':contract-id -- Contract id to read source:' \
&& ret=0
;;
(compose)
_arguments "${_arguments_options[@]}" \
'*-t+[]:NODE_TYPES: ' \
'*--node-type=[]:NODE_TYPES: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':contract-id -- Contract id to read source:' \
'*::outpoints -- Bitcoin transaction UTXOs which will be spent by the transfer:' \
':output -- Output file to save consignment prototype to:' \
&& ret=0
;;
(transfer)
_arguments "${_arguments_options[@]}" \
'-o+[Output file to save the PSBT updated with state transition(s) information. If not given, the source PSBT file is overwritten]:PSBT_OUT: ' \
'--out=[Output file to save the PSBT updated with state transition(s) information. If not given, the source PSBT file is overwritten]:PSBT_OUT: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':contract-id -- Contract id under which the main state transfer is happening:' \
':transition -- File containing main state transition for the transfer:' \
':psbt-in -- Input file containing PSBT of the transfer witness transaction:' \
&& ret=0
;;
(finalize)
_arguments "${_arguments_options[@]}" \
'-s+[Bifrost server to send state transfer to]:SEND: ' \
'--send=[Bifrost server to send state transfer to]:SEND: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':psbt -- The final PSBT (not modified):' \
':consignment-in -- State transfer consignment draft file prepared with `compose` command:' \
'::consignment-out -- Output file to save the final consignment. If not given, the source consignment file is overwritten:' \
'*::endseals -- Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-n+[Blockchain to use]:CHAIN: ' \
'--chain=[Blockchain to use]:CHAIN: ' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
'*::subcommand -- The subcommand whose help message to display:' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_rgb-cli_commands] )) ||
_rgb-cli_commands() {
    local commands; commands=(
'register:Add new contract to the node' \
'contracts:List all known contract ids' \
'state:Query contract state' \
'contract:Request contract source' \
'compose:Build state transfer consignment draft' \
'transfer:Add transfer information to PSBT' \
'finalize:Finalize and (optionally) send consignment to beneficiary' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rgb-cli commands' commands "$@"
}
(( $+functions[_rgb-cli__compose_commands] )) ||
_rgb-cli__compose_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli compose commands' commands "$@"
}
(( $+functions[_rgb-cli__contract_commands] )) ||
_rgb-cli__contract_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli contract commands' commands "$@"
}
(( $+functions[_rgb-cli__contracts_commands] )) ||
_rgb-cli__contracts_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli contracts commands' commands "$@"
}
(( $+functions[_rgb-cli__finalize_commands] )) ||
_rgb-cli__finalize_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli finalize commands' commands "$@"
}
(( $+functions[_rgb-cli__help_commands] )) ||
_rgb-cli__help_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli help commands' commands "$@"
}
(( $+functions[_rgb-cli__register_commands] )) ||
_rgb-cli__register_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli register commands' commands "$@"
}
(( $+functions[_rgb-cli__state_commands] )) ||
_rgb-cli__state_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli state commands' commands "$@"
}
(( $+functions[_rgb-cli__transfer_commands] )) ||
_rgb-cli__transfer_commands() {
    local commands; commands=()
    _describe -t commands 'rgb-cli transfer commands' commands "$@"
}

_rgb-cli "$@"
