//! $0 complete
use crate::command::CmdArg;
use crate::command::{FrCmds, FrArgs};
use std::io::stdout;


pub(crate) fn run(carg: CmdArg) -> Result<(), anyhow::Error>
{
	// Split up
	let CmdArg { clargs, config: _, version: _ } = carg;

	// Extract our own args
	let args = match clargs.command {
		FrCmds::Complete(a) => a,
		_ => unreachable!("I'm a complete, why does it think I'm not??"),
	};

	// It'll've given us a shell if we got here.
	use clap::CommandFactory as _;
	use clap_complete::generate;
	let mut cmd = FrArgs::command();
	let cmdname = crate::util::cmdname();
	generate(args.shell, &mut cmd, cmdname, &mut stdout());

	Ok(())
}
