use crate::ssh::ssh_config::security::validate_control_path;
use crate::ssh::ssh_config::types::SshHostConfig;
use anyhow::Result;
pub(super) fn parse_control_option(
host: &mut SshHostConfig,
keyword: &str,
args: &[String],
line_number: usize,
) -> Result<()> {
match keyword {
"controlmaster" => {
if args.is_empty() {
anyhow::bail!("ControlMaster requires a value at line {line_number}");
}
host.control_master = Some(args[0].clone());
}
"controlpath" => {
if args.is_empty() {
anyhow::bail!("ControlPath requires a value at line {line_number}");
}
let path = args[0].clone();
validate_control_path(&path, line_number)?;
host.control_path = Some(path);
}
"controlpersist" => {
if args.is_empty() {
anyhow::bail!("ControlPersist requires a value at line {line_number}");
}
host.control_persist = Some(args[0].clone());
}
_ => unreachable!("Unexpected keyword in parse_control_option: {}", keyword),
}
Ok(())
}