use crate::ssh::ssh_config::types::SshHostConfig;
use anyhow::{Context, Result};
pub(super) fn parse_basic_option(
host: &mut SshHostConfig,
keyword: &str,
args: &[String],
line_number: usize,
) -> Result<()> {
match keyword {
"hostname" => {
if args.is_empty() {
anyhow::bail!("HostName requires a value at line {line_number}");
}
host.hostname = Some(args[0].clone());
}
"user" => {
if args.is_empty() {
anyhow::bail!("User requires a value at line {line_number}");
}
host.user = Some(args[0].clone());
}
"port" => {
if args.is_empty() {
anyhow::bail!("Port requires a value at line {line_number}");
}
let port: u16 = args[0].parse().with_context(|| {
format!("Invalid port number '{}' at line {}", args[0], line_number)
})?;
host.port = Some(port);
}
_ => unreachable!("Unexpected keyword in parse_basic_option: {}", keyword),
}
Ok(())
}