# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
function __fish_ordinaryd_global_optspecs
	string join \n data-dir= stdio-logs stdio-pretty stdio-json json-logs log-level= with-span-timing log-file-rotation= log-size h/help V/version
end

function __fish_ordinaryd_needs_command
	# Figure out if the current invocation already has a command.
	set -l cmd (commandline -opc)
	set -e cmd[1]
	argparse -s (__fish_ordinaryd_global_optspecs) -- $cmd 2>/dev/null
	or return
	if set -q argv[1]
		# Also print the command, so this can be used to figure out what it is.
		echo $argv[1]
		return 1
	end
	return 0
end

function __fish_ordinaryd_using_subcommand
	set -l cmd (__fish_ordinaryd_needs_command)
	test -z "$cmd"
	and return 1
	contains -- $cmd[1] $argv
end

complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l data-dir -d 'specify the data directory' -r
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l log-level -d 'base log level for every component' -r -f -a "error\t''
warn\t''
info\t''
debug\t''
trace\t''"
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l log-file-rotation -d 'rate at which new log files are generated' -r -f -a "day\t''
hour\t''
minute\t''
never\t''"
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l stdio-logs -d 'logs events to stdio'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l stdio-pretty -d 'whether to pretty print stdio logs'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l stdio-json -d 'whether to print stdio logs as json'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l json-logs -d 'persists JSON formatted log lines to <data-dir>/logs/'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l with-span-timing -d 'dictates whether timing information should be logged'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -l log-size -d 'whether storage sizes are logged'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -s h -l help -d 'Print help'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -s V -l version -d 'Print version'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -f -a "init" -d 'initialize the environment for an Ordinary API server'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -f -a "api" -d 'start the Ordinary API server'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -f -a "app" -d 'start an Ordinary Application server'
complete -c ordinaryd -n "__fish_ordinaryd_needs_command" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l environment -d 'environment (e.g production, development, staging)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l storage-size -d 'Storage size in bytes (rounded up to nearest OS page size)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l api-domain -d 'domain name for API console' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l password -d 'instance user password' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l api-contacts -d 'contacts for the API domain cert provisioning' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l app-domains -d 'domains that apps can subdomain off of' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l privileged-domains -d 'list of applications that have access to API server level commands (i.e. API server invite token generation)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l data-dir -d 'specify the data directory' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l log-level -d 'base log level for every component' -r -f -a "error\t''
warn\t''
info\t''
debug\t''
trace\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l log-file-rotation -d 'rate at which new log files are generated' -r -f -a "day\t''
hour\t''
minute\t''
never\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l mfa-stored -d 'store the MFA key locally instead of copying a QR code'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l stdio-logs -d 'logs events to stdio'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l stdio-pretty -d 'whether to pretty print stdio logs'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l stdio-json -d 'whether to print stdio logs as json'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l json-logs -d 'persists JSON formatted log lines to <data-dir>/logs/'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l with-span-timing -d 'dictates whether timing information should be logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -l log-size -d 'whether storage sizes are logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand init" -s V -l version -d 'Print version'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l environment -d 'environment (e.g production, development, staging)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l storage-size -d 'Storage size in bytes (rounded up to nearest OS page size)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l provision -d 'what mode TLS certs should be provisioned in' -r -f -a "staging\t''
production\t''
localhost\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l port -d 'specify HTTP(s) port for server' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l redirect-port -d 'specify HTTP port for server when running in secure mode' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l redacted-header-hash -d '"none" | "blake2" | "blake3"' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-sync-interval-min -d 'min duration between log indexing operations. (seconds)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-sync-interval-max -d 'duration between log indexing operations. (seconds)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-max-ttl-days -d 'max period of time logs are indexed/stored' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l data-dir -d 'specify the data directory' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-level -d 'base log level for every component' -r -f -a "error\t''
warn\t''
info\t''
debug\t''
trace\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-file-rotation -d 'rate at which new log files are generated' -r -f -a "day\t''
hour\t''
minute\t''
never\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l insecure -d 'run without HTTPS'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l insecure-cookies -d 'run with insecure cookies'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-headers -d 'whether HTTP request and response headers are logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-ips -d 'whether IP Addresses are logged with HTTP requests'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l dedicated-ports -d 'give each app its own port'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-index -d 'whether to index logs so they can be queried'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l swagger -d 'Storage size in bytes (rounded up to nearest OS page size)'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l stdio-logs -d 'logs events to stdio'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l stdio-pretty -d 'whether to pretty print stdio logs'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l stdio-json -d 'whether to print stdio logs as json'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l json-logs -d 'persists JSON formatted log lines to <data-dir>/logs/'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l with-span-timing -d 'dictates whether timing information should be logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -l log-size -d 'whether storage sizes are logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -s h -l help -d 'Print help'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand api" -s V -l version -d 'Print version'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l provision -d 'what mode TLS certs should be provisioned in' -r -f -a "staging\t''
production\t''
localhost\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l port -d 'specify HTTP(s) port for server' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l redirect-port -d 'specify HTTP port for server when running in secure mode' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l redacted-header-hash -d '"none" | "blake2" | "blake3"' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l project-dir -d 'for running a standalone project. (project must already be built)' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l domain-override -d 'use a different domain than what\'s in the `ordinary.json`' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l data-dir -d 'specify the data directory' -r
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l log-level -d 'base log level for every component' -r -f -a "error\t''
warn\t''
info\t''
debug\t''
trace\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l log-file-rotation -d 'rate at which new log files are generated' -r -f -a "day\t''
hour\t''
minute\t''
never\t''"
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l insecure -d 'run without HTTPS'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l insecure-cookies -d 'run with insecure cookies'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l log-headers -d 'whether HTTP request and response headers are logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l log-ips -d 'whether IP Addresses are logged with HTTP requests'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l stdio-logs -d 'logs events to stdio'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l stdio-pretty -d 'whether to pretty print stdio logs'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l stdio-json -d 'whether to print stdio logs as json'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l json-logs -d 'persists JSON formatted log lines to <data-dir>/logs/'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l with-span-timing -d 'dictates whether timing information should be logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -l log-size -d 'whether storage sizes are logged'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -s h -l help -d 'Print help'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand app" -s V -l version -d 'Print version'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand help; and not __fish_seen_subcommand_from init api app help" -f -a "init" -d 'initialize the environment for an Ordinary API server'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand help; and not __fish_seen_subcommand_from init api app help" -f -a "api" -d 'start the Ordinary API server'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand help; and not __fish_seen_subcommand_from init api app help" -f -a "app" -d 'start an Ordinary Application server'
complete -c ordinaryd -n "__fish_ordinaryd_using_subcommand help; and not __fish_seen_subcommand_from init api app help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
