#compdef ordinaryd

autoload -U is-at-least

_ordinaryd() {
    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[@]}" : \
'--data-dir=[specify the data directory]:DATA_DIR:_default' \
'--log-level=[base log level for every component]:LOG_LEVEL:(error warn info debug trace)' \
'--log-file-rotation=[rate at which new log files are generated]:LOG_FILE_ROTATION:(day hour minute never)' \
'--stdio-logs[logs events to stdio]' \
'--stdio-pretty[whether to pretty print stdio logs]' \
'--stdio-json[whether to print stdio logs as json]' \
'--json-logs[persists JSON formatted log lines to <data-dir>/logs/]' \
'--with-span-timing[dictates whether timing information should be logged]' \
'--log-size[whether storage sizes are logged]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_ordinaryd_commands" \
"*::: :->ordinaryd" \
&& ret=0
    case $state in
    (ordinaryd)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ordinaryd-command-$line[1]:"
        case $line[1] in
            (init)
_arguments "${_arguments_options[@]}" : \
'--environment=[environment (e.g production, development, staging)]:ENVIRONMENT:_default' \
'--storage-size=[Storage size in bytes (rounded up to nearest OS page size)]:STORAGE_SIZE:_default' \
'--api-domain=[domain name for API console]:API_DOMAIN:_default' \
'--password=[instance user password]:PASSWORD:_default' \
'*--api-contacts=[contacts for the API domain cert provisioning]:API_CONTACTS:_default' \
'*--app-domains=[domains that apps can subdomain off of]:APP_DOMAINS:_default' \
'*--privileged-domains=[list of applications that have access to API server level commands (i.e. API server invite token generation)]::PRIVILEGED_DOMAINS:_default' \
'--data-dir=[specify the data directory]:DATA_DIR:_default' \
'--log-level=[base log level for every component]:LOG_LEVEL:(error warn info debug trace)' \
'--log-file-rotation=[rate at which new log files are generated]:LOG_FILE_ROTATION:(day hour minute never)' \
'--mfa-stored[store the MFA key locally instead of copying a QR code]' \
'--stdio-logs[logs events to stdio]' \
'--stdio-pretty[whether to pretty print stdio logs]' \
'--stdio-json[whether to print stdio logs as json]' \
'--json-logs[persists JSON formatted log lines to <data-dir>/logs/]' \
'--with-span-timing[dictates whether timing information should be logged]' \
'--log-size[whether storage sizes are logged]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(api)
_arguments "${_arguments_options[@]}" : \
'--environment=[environment (e.g production, development, staging)]:ENVIRONMENT:_default' \
'--storage-size=[Storage size in bytes (rounded up to nearest OS page size)]:STORAGE_SIZE:_default' \
'--provision=[what mode TLS certs should be provisioned in]:PROVISION:(staging production localhost)' \
'--port=[specify HTTP(s) port for server]:PORT:_default' \
'--redirect-port=[specify HTTP port for server when running in secure mode]:REDIRECT_PORT:_default' \
'--redacted-header-hash=["none" | "blake2" | "blake3"]:REDACTED_HEADER_HASH:_default' \
'--log-sync-interval-min=[min duration between log indexing operations. (seconds)]:LOG_SYNC_INTERVAL_MIN:_default' \
'--log-sync-interval-max=[duration between log indexing operations. (seconds)]:LOG_SYNC_INTERVAL_MAX:_default' \
'--log-max-ttl-days=[max period of time logs are indexed/stored]:LOG_MAX_TTL_DAYS:_default' \
'--data-dir=[specify the data directory]:DATA_DIR:_default' \
'--log-level=[base log level for every component]:LOG_LEVEL:(error warn info debug trace)' \
'--log-file-rotation=[rate at which new log files are generated]:LOG_FILE_ROTATION:(day hour minute never)' \
'--insecure[run without HTTPS]' \
'--insecure-cookies[run with insecure cookies]' \
'--log-headers[whether HTTP request and response headers are logged]' \
'--log-ips[whether IP Addresses are logged with HTTP requests]' \
'--dedicated-ports[give each app its own port]' \
'--log-index[whether to index logs so they can be queried]' \
'--swagger[Storage size in bytes (rounded up to nearest OS page size)]' \
'--stdio-logs[logs events to stdio]' \
'--stdio-pretty[whether to pretty print stdio logs]' \
'--stdio-json[whether to print stdio logs as json]' \
'--json-logs[persists JSON formatted log lines to <data-dir>/logs/]' \
'--with-span-timing[dictates whether timing information should be logged]' \
'--log-size[whether storage sizes are logged]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(app)
_arguments "${_arguments_options[@]}" : \
'--provision=[what mode TLS certs should be provisioned in]:PROVISION:(staging production localhost)' \
'--port=[specify HTTP(s) port for server]:PORT:_default' \
'--redirect-port=[specify HTTP port for server when running in secure mode]:REDIRECT_PORT:_default' \
'--redacted-header-hash=["none" | "blake2" | "blake3"]:REDACTED_HEADER_HASH:_default' \
'-p+[for running a standalone project. (project must already be built)]:PROJECT:_default' \
'--project=[for running a standalone project. (project must already be built)]:PROJECT:_default' \
'--domain-override=[use a different domain than what'\''s in the \`ordinary.json\`]:DOMAIN_OVERRIDE:_default' \
'--data-dir=[specify the data directory]:DATA_DIR:_default' \
'--log-level=[base log level for every component]:LOG_LEVEL:(error warn info debug trace)' \
'--log-file-rotation=[rate at which new log files are generated]:LOG_FILE_ROTATION:(day hour minute never)' \
'--insecure[run without HTTPS]' \
'--insecure-cookies[run with insecure cookies]' \
'--log-headers[whether HTTP request and response headers are logged]' \
'--log-ips[whether IP Addresses are logged with HTTP requests]' \
'--stdio-logs[logs events to stdio]' \
'--stdio-pretty[whether to pretty print stdio logs]' \
'--stdio-json[whether to print stdio logs as json]' \
'--json-logs[persists JSON formatted log lines to <data-dir>/logs/]' \
'--with-span-timing[dictates whether timing information should be logged]' \
'--log-size[whether storage sizes are logged]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_ordinaryd__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_ordinaryd_commands] )) ||
_ordinaryd_commands() {
    local commands; commands=(
'init:initialize the environment for an Ordinary API server' \
'api:start the Ordinary API server' \
'app:start an Ordinary Application server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ordinaryd commands' commands "$@"
}
(( $+functions[_ordinaryd__api_commands] )) ||
_ordinaryd__api_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd api commands' commands "$@"
}
(( $+functions[_ordinaryd__app_commands] )) ||
_ordinaryd__app_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd app commands' commands "$@"
}
(( $+functions[_ordinaryd__help_commands] )) ||
_ordinaryd__help_commands() {
    local commands; commands=(
'init:initialize the environment for an Ordinary API server' \
'api:start the Ordinary API server' \
'app:start an Ordinary Application server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ordinaryd help commands' commands "$@"
}
(( $+functions[_ordinaryd__help__api_commands] )) ||
_ordinaryd__help__api_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd help api commands' commands "$@"
}
(( $+functions[_ordinaryd__help__app_commands] )) ||
_ordinaryd__help__app_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd help app commands' commands "$@"
}
(( $+functions[_ordinaryd__help__help_commands] )) ||
_ordinaryd__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd help help commands' commands "$@"
}
(( $+functions[_ordinaryd__help__init_commands] )) ||
_ordinaryd__help__init_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd help init commands' commands "$@"
}
(( $+functions[_ordinaryd__init_commands] )) ||
_ordinaryd__init_commands() {
    local commands; commands=()
    _describe -t commands 'ordinaryd init commands' commands "$@"
}

if [ "$funcstack[1]" = "_ordinaryd" ]; then
    _ordinaryd "$@"
else
    compdef _ordinaryd ordinaryd
fi
