# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
function __fish_kdlfmt_global_optspecs
	string join \n log-level= h/help V/version
end

function __fish_kdlfmt_needs_command
	# Figure out if the current invocation already has a command.
	set -l cmd (commandline -opc)
	set -e cmd[1]
	argparse -s (__fish_kdlfmt_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_kdlfmt_using_subcommand
	set -l cmd (__fish_kdlfmt_needs_command)
	test -z "$cmd"
	and return 1
	contains -- $cmd[1] $argv
end

complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -l log-level -r -f -a "trace\t''
debug\t''
info\t''
warn\t''
error\t''
off\t''"
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -s h -l help -d 'Print help'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -s V -l version -d 'Print version'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -f -a "format" -d 'Format kdl files'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -f -a "check" -d 'Validate files are formatted'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -f -a "init" -d 'Initialize formatter config'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -f -a "completions" -d 'Generate shell completions'
complete -c kdlfmt -n "__fish_kdlfmt_needs_command" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -l kdl-version -d 'kdl specification to use' -r -f -a "v1\t''
v2\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -l config -d 'Path to config file' -r -F
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -l log-level -r -f -a "trace\t''
debug\t''
info\t''
warn\t''
error\t''
off\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -l stdin -d 'Read from stdin and print to stdout'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand format" -s V -l version -d 'Print version'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -l kdl-version -d 'kdl specification to use' -r -f -a "v1\t''
v2\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -l config -d 'Path to config file' -r -F
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -l log-level -r -f -a "trace\t''
debug\t''
info\t''
warn\t''
error\t''
off\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -l stdin -d 'Read from stdin and print to stdout'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand check" -s V -l version -d 'Print version'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand init" -l kdl-version -d 'kdl specification to use' -r -f -a "v1\t''
v2\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand init" -l log-level -r -f -a "trace\t''
debug\t''
info\t''
warn\t''
error\t''
off\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand init" -l force -d 'Create config even if one already exists in current directory'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand init" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand init" -s V -l version -d 'Print version'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand completions" -l log-level -r -f -a "trace\t''
debug\t''
info\t''
warn\t''
error\t''
off\t''"
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand completions" -s h -l help -d 'Print help'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand completions" -s V -l version -d 'Print version'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand help; and not __fish_seen_subcommand_from format check init completions help" -f -a "format" -d 'Format kdl files'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand help; and not __fish_seen_subcommand_from format check init completions help" -f -a "check" -d 'Validate files are formatted'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand help; and not __fish_seen_subcommand_from format check init completions help" -f -a "init" -d 'Initialize formatter config'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand help; and not __fish_seen_subcommand_from format check init completions help" -f -a "completions" -d 'Generate shell completions'
complete -c kdlfmt -n "__fish_kdlfmt_using_subcommand help; and not __fish_seen_subcommand_from format check init completions help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
