use clap::Parser;
use crate::clap_shim;
#[derive(Debug, Parser)]
#[command(name = "mkit switch", about = "Switch branches (git switch).")]
struct SwitchOpts {
#[arg(short = 'c', value_name = "NEW", conflicts_with = "create_force")]
create: Option<String>,
#[arg(short = 'C', value_name = "NEW")]
create_force: Option<String>,
target: Option<String>,
}
#[must_use]
pub fn run(args: &[String]) -> u8 {
let opts = match clap_shim::parse::<SwitchOpts>("mkit switch", args) {
Ok(o) => o,
Err(code) => return code,
};
let has_create = opts.create.is_some() || opts.create_force.is_some();
let mut fwd: Vec<String> = Vec::new();
if let Some(new) = opts.create.as_deref() {
fwd.push("-b".to_owned());
fwd.push(new.to_owned());
} else if let Some(new) = opts.create_force.as_deref() {
fwd.push("-B".to_owned());
fwd.push(new.to_owned());
}
match opts.target.as_deref() {
Some(t) => fwd.push(t.to_owned()),
None if !has_create => {
return super::usage_error("usage: mkit switch [-c|-C <new>] <branch>");
}
None => {}
}
super::checkout::run(&fwd)
}