#compdef lnp-cli

autoload -U is-at-least

_lnp-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: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
":: :_lnp-cli_commands" \
"*::: :->lnp-cli" \
&& ret=0
    case $state in
    (lnp-cli)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:lnp-cli-command-$line[1]:"
        case $line[1] in
            (listen)
_arguments "${_arguments_options[@]}" \
'-i+[IPv4 or IPv6 address to bind to]:IP_ADDR: ' \
'--ip=[IPv4 or IPv6 address to bind to]:IP_ADDR: ' \
'-p+[Port to use; defaults to the native LN port]:PORT: ' \
'--port=[Port to use; defaults to the native LN port]:PORT: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'(--bifrost)--bolt[Use BOLT lightning network protocol]' \
'--bifrost[Use Bifrost lightning network protocol]' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
&& ret=0
;;
(connect)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':peer -- Address of the remote node, in '\''<public_key>@<ipv4>|<ipv6>|<onionv2>|<onionv3>\[\:<port>\]'\'' format:' \
&& ret=0
;;
(ping)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'(--bifrost)--bolt[Use BOLT lightning network protocol]' \
'--bifrost[Use Bifrost lightning network protocol]' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':peer -- Public key (id) of the remote node:' \
&& ret=0
;;
(info)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'(--bifrost)--bolt[Use BOLT lightning network protocol]' \
'--bifrost[Use Bifrost lightning network protocol]' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
'::subject -- Remote peer address or temporary/permanent/short channel id. If absent, returns information about the node itself:' \
&& ret=0
;;
(funds)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
&& ret=0
;;
(peers)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
&& ret=0
;;
(channels)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
&& ret=0
;;
(open)
_arguments "${_arguments_options[@]}" \
'--pay=[Amount of millisatoshis to pay to the remote peer at channel opening]:PUSH_MSAT: ' \
'--fee-rate=[Sets fee rate for the channel transacitons]:FEE_RATE: ' \
'--announce-channel=[Make channel public and route payments]:ANNOUNCE_CHANNEL: ' \
'--channel-type=[Channel type as defined in BOLT-2]:CHANNEL_TYPE: ' \
'--dust-limit=[The threshold below which outputs on transactions broadcast by sender will be omitted]:DUST_LIMIT: ' \
'--to-self-delay=[The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction]:TO_SELF_DELAY: ' \
'--htlc-max-count=[The maximum number of the received HTLCs]:HTLC_MAX_COUNT: ' \
'--htlc-min-value=[Indicates the smallest value of an HTLC this node will accept, in milli-satoshi]:HTLC_MIN_VALUE: ' \
'--htlc-max-total-value=[The maximum inbound HTLC value in flight towards this node, in milli-satoshi]:HTLC_MAX_TOTAL_VALUE: ' \
'--channel-reserve=[The minimum value unencumbered by HTLCs for the counterparty to keep in the channel, in satoshis]:CHANNEL_RESERVE: ' \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':peer -- Address of the remote node, in '\''<public_key>@<ipv4>|<ipv6>|<onionv2>|<onionv3>\[\:<port>\]'\'' format:' \
':funding-sat -- Amount of satoshis to allocate to the channel (the actual allocation will happen later using `fund` command after the channel acceptance):' \
&& ret=0
;;
(invoice)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':amount -- Asset amount to invoice, in atomic unit (satoshis or smallest asset unit type):' \
'::asset -- Asset ticker in which the invoice should be issued:' \
&& ret=0
;;
(pay)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
':invoice -- Invoice bech32 string:' \
':channel -- Channel from which the payment should happen:' \
'::amount-msat -- Amount of milli-satoshis to pay. Required for invoices lacking amount. Overrides amount provided by the invoice:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'--rpc=[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \
'*-v[Set verbosity level]' \
'*--verbose[Set verbosity level]' \
'*::subcommand -- The subcommand whose help message to display:' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_lnp-cli_commands] )) ||
_lnp-cli_commands() {
    local commands; commands=(
'listen:Bind to a socket and start listening for incoming LN peer connections' \
'connect:Connect to the remote lightning network peer' \
'ping:Ping remote peer (must be already connected)' \
'info:General information about the running node' \
'funds:Lists all funds available for channel creation with the list of assets and provides information about funding points (bitcoin address or UTXO for RGB assets)' \
'peers:Lists existing peer connections' \
'channels:Lists existing channels' \
'open:Opens a new channel with a remote peer, which must be already connected' \
'invoice:Create an invoice' \
'pay:Pay the invoice' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'lnp-cli commands' commands "$@"
}
(( $+functions[_lnp-cli__channels_commands] )) ||
_lnp-cli__channels_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli channels commands' commands "$@"
}
(( $+functions[_lnp-cli__connect_commands] )) ||
_lnp-cli__connect_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli connect commands' commands "$@"
}
(( $+functions[_lnp-cli__funds_commands] )) ||
_lnp-cli__funds_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli funds commands' commands "$@"
}
(( $+functions[_lnp-cli__help_commands] )) ||
_lnp-cli__help_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli help commands' commands "$@"
}
(( $+functions[_lnp-cli__info_commands] )) ||
_lnp-cli__info_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli info commands' commands "$@"
}
(( $+functions[_lnp-cli__invoice_commands] )) ||
_lnp-cli__invoice_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli invoice commands' commands "$@"
}
(( $+functions[_lnp-cli__listen_commands] )) ||
_lnp-cli__listen_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli listen commands' commands "$@"
}
(( $+functions[_lnp-cli__open_commands] )) ||
_lnp-cli__open_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli open commands' commands "$@"
}
(( $+functions[_lnp-cli__pay_commands] )) ||
_lnp-cli__pay_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli pay commands' commands "$@"
}
(( $+functions[_lnp-cli__peers_commands] )) ||
_lnp-cli__peers_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli peers commands' commands "$@"
}
(( $+functions[_lnp-cli__ping_commands] )) ||
_lnp-cli__ping_commands() {
    local commands; commands=()
    _describe -t commands 'lnp-cli ping commands' commands "$@"
}

_lnp-cli "$@"
