# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
function __fish_ingredients_global_optspecs
	string join \n h/help
end

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

complete -c ingredients -n "__fish_ingredients_needs_command" -s h -l help -d 'Print help'
complete -c ingredients -n "__fish_ingredients_needs_command" -f -a "report" -d 'Compare a crate against the contents of the upstream version control system'
complete -c ingredients -n "__fish_ingredients_needs_command" -f -a "diff" -d 'Compare two versions of a crate'
complete -c ingredients -n "__fish_ingredients_needs_command" -f -a "completions"
complete -c ingredients -n "__fish_ingredients_needs_command" -f -a "manual"
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -l format -d 'Output format' -r -f -a "plain\t''
verbose\t''
json\t''"
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -l severity -d 'Minimum severity' -r -f -a "fatal\t'Fatal problems that prevent further processing'
error\t'Probable errors that require manual investigation'
warning\t'Potential issues that might or might not be harmless'
info\t'Additional information provided for some situations'
debug\t'Information only useful for debugging purposes'"
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s f -l file -d 'Path to local crate archive to use instead of downloading from crates.io' -r -F
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s u -l with-repository -d 'Provide repository URL if package.repository is missing or wrong' -r
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s p -l with-path-in-vcs -d 'Provide "path in VCS" if `.cargo_vcs_info.json` is missing or incomplete' -r
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s r -l with-vcs-ref -d 'Provide VCS ref if `.cargo_vcs_info.json` is missing or incomplete' -r
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s L -l diff-size-limit -d 'Override default file size limit (in bytes) for diff generation' -r
complete -c ingredients -n "__fish_ingredients_using_subcommand report" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l format -d 'Output format' -r -f -a "plain\t''
verbose\t''
json\t''"
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l severity -d 'Minimum severity' -r -f -a "fatal\t'Fatal problems that prevent further processing'
error\t'Probable errors that require manual investigation'
warning\t'Potential issues that might or might not be harmless'
info\t'Additional information provided for some situations'
debug\t'Information only useful for debugging purposes'"
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l old-file -d 'Path to local crate archive for old crate version' -r -F
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l new-file -d 'Path to local crate archive for new crate version' -r -F
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -s L -l diff-size-limit -d 'Override default file size limit (in bytes) for diff generation' -r
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l include-prereleases -d 'Include pre-releases when querying registry for available versions'
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -l include-yanked -d 'Include yanked versions when querying registry for available versions'
complete -c ingredients -n "__fish_ingredients_using_subcommand diff" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c ingredients -n "__fish_ingredients_using_subcommand completions" -s h -l help -d 'Print help'
complete -c ingredients -n "__fish_ingredients_using_subcommand manual" -s h -l help -d 'Print help'
