use std::io::Write;
use std::path::PathBuf;
use super::USAGE;
pub(crate) fn studio(
args: &mut impl Iterator<Item = String>,
out: &mut dyn Write,
) -> Result<(), String> {
let mut project: Option<PathBuf> = None;
for arg in args.by_ref() {
match arg.as_str() {
"-h" | "--help" => {
write!(out, "{USAGE}").map_err(|error| format!("cannot write usage: {error}"))?;
return Ok(());
}
_ if arg.starts_with('-') => return Err(format!("unexpected argument '{arg}'")),
_ if project.is_none() => project = Some(PathBuf::from(arg)),
_ => return Err("studio accepts at most one project path".to_owned()),
}
}
nichlink_studio::launch_with(project).map_err(|error| error.to_string())
}