#compdef amaru

autoload -U is-at-least

_amaru() {
    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[@]}" : \
'--color=[]:COLOR:_default' \
'--with-open-telemetry[]' \
'--with-json-traces[]' \
'-q[Do not initialize tracing library]' \
'--quiet[Do not initialize tracing library]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_amaru_commands" \
"*::: :->Amaru" \
&& ret=0
    case $state in
    (Amaru)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:amaru-command-$line[1]:"
        case $line[1] in
            (bootstrap)
_arguments "${_arguments_options[@]}" : \
'--chain-dir=[Path of the chain on-disk storage]:DIR:_files' \
'--ledger-dir=[Path of the ledger on-disk storage]:DIR:_files' \
'--epoch=[The target bootstrap epoch; this is the epoch Amaru will start from]:UINT:_default' \
'--network=[Network to bootstrap the node for]:mainnet|preprod|preview|testnet_<U32>:_default' \
'--consensus-security-param=[The maximum depth of a rollback, also known as the security parameter '\''k'\'']:UINT:_default' \
'--epoch-length-scale-factor=[Multiplier applied to the \`consensus_security_param\` to determine the epoch length]:UINT:_default' \
'--active-slot-coeff-inverse=[Inverse of the active slot coefficient (i.e. 1/f);]:UINT:_default' \
'--max-lovelace-supply=[Maximum supply of Ada, in lovelace (1 Ada = 1,000,000 Lovelace)]:LOVELACE:_default' \
'--slots-per-kes-period=[Number of slots for a single KES validity period]:UINT:_default' \
'--max-kes-evolution=[Maximum number of KES key evolution. Combined with SLOTS_PER_KES_PERIOD, these values indicates the validity period of a KES key before a new one is required]:U8:_default' \
'--system-start=[POSIX time (milliseconds) of the System Start]:MILLIS:_default' \
'-f[Forcefully erase and overwrite the ledger database if it already exists]' \
'--force[Forcefully erase and overwrite the ledger database if it already exists]' \
'--help-global-parameters[Show global network parameter overrides, for custom testnets]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(dump-chain-db)
_arguments "${_arguments_options[@]}" : \
'--chain-dir=[The path to the chain database to dump]:DIR:_files' \
'--network=[Network for which we are importing headers]:mainnet|preprod|preview|testnet_<U32>:_default' \
'-a+[]:SLOT.HEADER_HASH or HEADER_HASH:_default' \
'--ancestors=[]:SLOT.HEADER_HASH or HEADER_HASH:_default' \
'-c+[]:SLOT.HEADER_HASH or HEADER_HASH:_default' \
'--children=[]:SLOT.HEADER_HASH or HEADER_HASH:_default' \
'-H[]' \
'--headers[]' \
'-p[]' \
'--parents-children[]' \
'-n[]' \
'--nonces[]' \
'-B[]' \
'--blocks[]' \
'-b[]' \
'--best-chain[]' \
'-f[]' \
'--find-best-candidate[]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(remove-validation-status)
_arguments "${_arguments_options[@]}" : \
'--chain-dir=[The path to the chain store database to remove the validation status from]:DIR:_files' \
'--network=[Network of the underlying chain database]:mainnet|preprod|preview|testnet_<U32>:_default' \
'-h[Print help]' \
'--help[Print help]' \
'*::blocks -- The blocks from which to remove the validation status:_default' \
&& ret=0
;;
(remove-chain)
_arguments "${_arguments_options[@]}" : \
'--from-point=[The point from which onward to remove the chain]:SLOT.HEADER_HASH:_default' \
'--chain-dir=[The path to the chain store database to remove the validation status from]:DIR:_files' \
'--network=[Network of the underlying chain database]:mainnet|preprod|preview|testnet_<U32>:_default' \
'--only-blocks[Remove only blocks]' \
'--only-validation-results[Remove only validation results]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(dump-traces-schema)
_arguments "${_arguments_options[@]}" : \
'-c[Compact JSON output (no pretty-printing)]' \
'--compact[Compact JSON output (no pretty-printing)]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(fetch-chain-headers)
_arguments "${_arguments_options[@]}" : \
'--headers-dir=[Path where to store fetched headers]:DIR:_files' \
'--network=[Network to fetch chain headers from]:mainnet|preprod|preview|testnet_<U32>:_default' \
'*--parent=[Parent point of the header to fetch]::SLOT.HEADER_HASH:_default' \
'--peer-address=[Address of the node to connect to for retrieving chain data]:HOSTNAME[:PORT]:_default' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(create-snapshots)
_arguments "${_arguments_options[@]}" : \
'--network=[The target network to choose from]:mainnet|preprod|preview|testnet_<U32>:_default' \
'--epoch=[The target epoch *after* bootstrap]:UINT:_default' \
'--dist-dir=[Distribution directory used for metadata, caches and temporary work files]:DIR:_files' \
'--snapshot-dir=[Directory where snapshot archives and materialized snapshot directories are written]:DIR:_files' \
'--cardano-node-config-dir=[Directory containing the cardano-node config.json and genesis files]:DIR:_files' \
'--cardano-node-db=[Use an existing local cardano-node database instead of downloading via Mithril]:DIR:_files' \
'*--snapshot=[An optional list of three snapshot points. The option may be repeated]:SLOT.HEADER_HASH::PARENT_SLOT.PARENT_HEADER_HASH:_default' \
'-f[Forcefully erase requested generated snapshot outputs and regenerate them]' \
'--force[Forcefully erase requested generated snapshot outputs and regenerate them]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(shell-completions)
_arguments "${_arguments_options[@]}" : \
'--output-dir=[]:OUTPUT_DIR:_files' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(migrate-chain-db)
_arguments "${_arguments_options[@]}" : \
'--chain-dir=[The path to the chain database to migrate]:DIR:_files' \
'--network=[Underlying network of the database to migrate]:mainnet|preprod|preview|testnet_<U32>:_default' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(reset-to-epoch)
_arguments "${_arguments_options[@]}" : \
'--ledger-dir=[The path to the ledger database to reset]:DIR:_files' \
'--network=[Network of the underlying chain database]:mainnet|preprod|preview|testnet_<U32>:_default' \
'-h[Print help]' \
'--help[Print help]' \
':epoch -- The epoch to reset to:_default' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
'--network=[The target network to run against]:mainnet|preprod|preview|testnet_<U32>:_default' \
'--chain-dir=[Path of the chain on-disk storage]:DIR:_files' \
'--ledger-dir=[Path of the ledger on-disk storage]:DIR:_files' \
'--listen-address=[The address to listen on for incoming connections]:HOSTNAME[:PORT]:_default' \
'--submit-api-address=[Address for the HTTP transaction submit API]:HOSTNAME[:PORT]:_default' \
'*--peer-address=[Upstream peer addresses to synchronize from]::HOSTNAME[:PORT]:_default' \
'--upstream-peers=[The number of upstream peers to connect to]:UINT:_default' \
'--downstream-peers=[The maximum number of downstream peers allowed to connect]:UINT:_default' \
'--max-extra-ledger-snapshots=[The maximum number of additional ledger snapshots to keep around]:UINT|all:_default' \
'--peer-removal-cooldown-secs=[After removing a misbehaving upstream peer, wait this many seconds before allowing it to be re-added]:UINT:_default' \
'--pid-file=[Path to the PID file managed by Amaru]:FILEPATH:_files' \
'--trace-buffer=[Stage graph trace buffer\: \`min_entries,max_total_bytes\` (e.g. \`100,1000000\`)]:MIN_ENTRIES,MAX_SIZE:_default' \
'--dump-trace-buffer=[Concatenate raw CBOR trace entries to this file when the node shuts down]:FILEPATH:_files' \
'--era-history=[Path to a JSON era history file overriding the network default]:FILEPATH:_files' \
'--consensus-security-param=[The maximum depth of a rollback, also known as the security parameter '\''k'\'']:UINT:_default' \
'--epoch-length-scale-factor=[Multiplier applied to the \`consensus_security_param\` to determine the epoch length]:UINT:_default' \
'--active-slot-coeff-inverse=[Inverse of the active slot coefficient (i.e. 1/f);]:UINT:_default' \
'--max-lovelace-supply=[Maximum supply of Ada, in lovelace (1 Ada = 1,000,000 Lovelace)]:LOVELACE:_default' \
'--slots-per-kes-period=[Number of slots for a single KES validity period]:UINT:_default' \
'--max-kes-evolution=[Maximum number of KES key evolution. Combined with SLOTS_PER_KES_PERIOD, these values indicates the validity period of a KES key before a new one is required]:U8:_default' \
'--system-start=[POSIX time (milliseconds) of the System Start]:MILLIS:_default' \
'--migrate-chain-db[Flag to automatically migrate the chain database if needed]' \
'--help-global-parameters[Show global network parameter overrides, for custom testnets]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_amaru__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:amaru-help-command-$line[1]:"
        case $line[1] in
            (bootstrap)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(dump-chain-db)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove-validation-status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove-chain)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(dump-traces-schema)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(fetch-chain-headers)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(create-snapshots)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(shell-completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(migrate-chain-db)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(reset-to-epoch)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_amaru_commands] )) ||
_amaru_commands() {
    local commands; commands=(
'bootstrap:Bootstrap the node with needed data.' \
'dump-chain-db:Dump the content of the chain database for troubleshooting purposes' \
'remove-validation-status:Remove the validation status of the given blocks from the chain database' \
'remove-chain:Remove the given chain fragment from the chain database' \
'dump-traces-schema:Dump all registered trace schemas as JSON Schema' \
'fetch-chain-headers:Fetch specified headers' \
'create-snapshots:Create the three consecutive epoch snapshots needed for bootstrap' \
'shell-completions:' \
'migrate-chain-db:Migrate the chain database to the current version' \
'reset-to-epoch:Reset the ledger database to the beginning of a specific epoch' \
'run:Run the node in all its glory' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'amaru commands' commands "$@"
}
(( $+functions[_amaru__subcmd__bootstrap_commands] )) ||
_amaru__subcmd__bootstrap_commands() {
    local commands; commands=()
    _describe -t commands 'amaru bootstrap commands' commands "$@"
}
(( $+functions[_amaru__subcmd__create-snapshots_commands] )) ||
_amaru__subcmd__create-snapshots_commands() {
    local commands; commands=()
    _describe -t commands 'amaru create-snapshots commands' commands "$@"
}
(( $+functions[_amaru__subcmd__dump-chain-db_commands] )) ||
_amaru__subcmd__dump-chain-db_commands() {
    local commands; commands=()
    _describe -t commands 'amaru dump-chain-db commands' commands "$@"
}
(( $+functions[_amaru__subcmd__dump-traces-schema_commands] )) ||
_amaru__subcmd__dump-traces-schema_commands() {
    local commands; commands=()
    _describe -t commands 'amaru dump-traces-schema commands' commands "$@"
}
(( $+functions[_amaru__subcmd__fetch-chain-headers_commands] )) ||
_amaru__subcmd__fetch-chain-headers_commands() {
    local commands; commands=()
    _describe -t commands 'amaru fetch-chain-headers commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help_commands] )) ||
_amaru__subcmd__help_commands() {
    local commands; commands=(
'bootstrap:Bootstrap the node with needed data.' \
'dump-chain-db:Dump the content of the chain database for troubleshooting purposes' \
'remove-validation-status:Remove the validation status of the given blocks from the chain database' \
'remove-chain:Remove the given chain fragment from the chain database' \
'dump-traces-schema:Dump all registered trace schemas as JSON Schema' \
'fetch-chain-headers:Fetch specified headers' \
'create-snapshots:Create the three consecutive epoch snapshots needed for bootstrap' \
'shell-completions:' \
'migrate-chain-db:Migrate the chain database to the current version' \
'reset-to-epoch:Reset the ledger database to the beginning of a specific epoch' \
'run:Run the node in all its glory' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'amaru help commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__bootstrap_commands] )) ||
_amaru__subcmd__help__subcmd__bootstrap_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help bootstrap commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__create-snapshots_commands] )) ||
_amaru__subcmd__help__subcmd__create-snapshots_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help create-snapshots commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__dump-chain-db_commands] )) ||
_amaru__subcmd__help__subcmd__dump-chain-db_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help dump-chain-db commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__dump-traces-schema_commands] )) ||
_amaru__subcmd__help__subcmd__dump-traces-schema_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help dump-traces-schema commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__fetch-chain-headers_commands] )) ||
_amaru__subcmd__help__subcmd__fetch-chain-headers_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help fetch-chain-headers commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__help_commands] )) ||
_amaru__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help help commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__migrate-chain-db_commands] )) ||
_amaru__subcmd__help__subcmd__migrate-chain-db_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help migrate-chain-db commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__remove-chain_commands] )) ||
_amaru__subcmd__help__subcmd__remove-chain_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help remove-chain commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__remove-validation-status_commands] )) ||
_amaru__subcmd__help__subcmd__remove-validation-status_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help remove-validation-status commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__reset-to-epoch_commands] )) ||
_amaru__subcmd__help__subcmd__reset-to-epoch_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help reset-to-epoch commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__run_commands] )) ||
_amaru__subcmd__help__subcmd__run_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help run commands' commands "$@"
}
(( $+functions[_amaru__subcmd__help__subcmd__shell-completions_commands] )) ||
_amaru__subcmd__help__subcmd__shell-completions_commands() {
    local commands; commands=()
    _describe -t commands 'amaru help shell-completions commands' commands "$@"
}
(( $+functions[_amaru__subcmd__migrate-chain-db_commands] )) ||
_amaru__subcmd__migrate-chain-db_commands() {
    local commands; commands=()
    _describe -t commands 'amaru migrate-chain-db commands' commands "$@"
}
(( $+functions[_amaru__subcmd__remove-chain_commands] )) ||
_amaru__subcmd__remove-chain_commands() {
    local commands; commands=()
    _describe -t commands 'amaru remove-chain commands' commands "$@"
}
(( $+functions[_amaru__subcmd__remove-validation-status_commands] )) ||
_amaru__subcmd__remove-validation-status_commands() {
    local commands; commands=()
    _describe -t commands 'amaru remove-validation-status commands' commands "$@"
}
(( $+functions[_amaru__subcmd__reset-to-epoch_commands] )) ||
_amaru__subcmd__reset-to-epoch_commands() {
    local commands; commands=()
    _describe -t commands 'amaru reset-to-epoch commands' commands "$@"
}
(( $+functions[_amaru__subcmd__run_commands] )) ||
_amaru__subcmd__run_commands() {
    local commands; commands=()
    _describe -t commands 'amaru run commands' commands "$@"
}
(( $+functions[_amaru__subcmd__shell-completions_commands] )) ||
_amaru__subcmd__shell-completions_commands() {
    local commands; commands=()
    _describe -t commands 'amaru shell-completions commands' commands "$@"
}

if [ "$funcstack[1]" = "_amaru" ]; then
    _amaru "$@"
else
    compdef _amaru amaru
fi
