diff --git a/p/src/commands/register.rs b/p/src/commands/register.rs index 25472c6..74d7d05 100644 --- a/p/src/commands/register.rs +++ b/p/src/commands/register.rs @@ -15,7 +15,8 @@ pub fn execute(connection: &str, name: Option<&str>) -> Result<()> { anyhow::bail!( "a worker named '{}' is already registered\n\ Use 'p default {}' to make it the default, or choose a different name with -n", - name, name + name, + name ); } diff --git a/p/src/commands/workers.rs b/p/src/commands/workers.rs index 75866dd..878aed0 100644 --- a/p/src/commands/workers.rs +++ b/p/src/commands/workers.rs @@ -10,12 +10,28 @@ pub fn execute(check: bool) -> Result<()> { return Ok(()); } - let name_w = cfg.workers.iter().map(|w| w.name.len()).max().unwrap_or(0).max(4); - let conn_w = cfg.workers.iter().map(|w| w.connection.len()).max().unwrap_or(0).max(10); + let name_w = cfg + .workers + .iter() + .map(|w| w.name.len()) + .max() + .unwrap_or(0) + .max(4); + let conn_w = cfg + .workers + .iter() + .map(|w| w.connection.len()) + .max() + .unwrap_or(0) + .max(10); if check { println!(" {: Result<()> { let prefix = if is_default { "* " } else { " " }; if check { - let status = if ssh::is_reachable(worker) { "reachable" } else { "unreachable" }; - println!("{}{: Result { } let content = std::fs::read_to_string(&path) .map_err(|e| anyhow::anyhow!("failed to read {}: {}", path.display(), e))?; - serde_yaml::from_str(&content) - .map_err(|e| anyhow::anyhow!("failed to parse config: {}", e)) + serde_yaml::from_str(&content).map_err(|e| anyhow::anyhow!("failed to parse config: {}", e)) } pub fn save(config: &Config) -> Result<()> { @@ -65,11 +64,11 @@ impl Config { Some(n) => self .get_worker(n) .ok_or_else(|| anyhow::anyhow!("unknown worker '{}'", n)), - None => self - .default_worker() - .ok_or_else(|| anyhow::anyhow!( + None => self.default_worker().ok_or_else(|| { + anyhow::anyhow!( "no default worker configured — run 'p register ' first" - )), + ) + }), } } } diff --git a/p/src/db.rs b/p/src/db.rs index debe337..5f59a85 100644 --- a/p/src/db.rs +++ b/p/src/db.rs @@ -37,8 +37,8 @@ pub fn load(id: &str) -> Result> { if !path.exists() { return Ok(None); } - let content = std::fs::read_to_string(&path) - .with_context(|| format!("failed to read job {}", id))?; + let content = + std::fs::read_to_string(&path).with_context(|| format!("failed to read job {}", id))?; serde_json::from_str(&content) .with_context(|| format!("failed to parse job {}", id)) .map(Some) @@ -91,7 +91,8 @@ pub fn list() -> Result> { continue; } match std::fs::read_to_string(&path).and_then(|c| { - serde_json::from_str::(&c).map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e)) + serde_json::from_str::(&c) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e)) }) { Ok(job) => jobs.push(job), Err(e) => eprintln!("warning: skipping {:?}: {}", path, e), @@ -106,8 +107,7 @@ pub fn list() -> Result> { pub fn delete(id: &str) -> Result<()> { let path = job_path(id)?; if path.exists() { - std::fs::remove_file(&path) - .with_context(|| format!("failed to delete job {}", id))?; + std::fs::remove_file(&path).with_context(|| format!("failed to delete job {}", id))?; } Ok(()) } diff --git a/p/src/main.rs b/p/src/main.rs index b754a14..0b74711 100644 --- a/p/src/main.rs +++ b/p/src/main.rs @@ -31,7 +31,10 @@ fn main() -> Result<()> { match arg.as_str() { "-n" | "--no-sync" => no_sync = true, flag if flag.starts_with('-') => { - eprintln!("error: unknown flag '{}'\nusage: p [-n] [] -- ", flag); + eprintln!( + "error: unknown flag '{}'\nusage: p [-n] [] -- ", + flag + ); std::process::exit(1); } name => { @@ -54,9 +57,11 @@ fn main() -> Result<()> { cli::Command::Attach { job_id } => commands::attach::execute(&job_id), cli::Command::Logs { job_id, follow } => commands::logs::execute(&job_id, follow), cli::Command::Stop { job_id } => commands::stop::execute(&job_id), - cli::Command::Pull { job_id, remote_path, local_dest } => { - commands::pull::execute(&job_id, &remote_path, local_dest.as_deref()) - } + cli::Command::Pull { + job_id, + remote_path, + local_dest, + } => commands::pull::execute(&job_id, &remote_path, local_dest.as_deref()), cli::Command::Rm { job_id, force } => commands::rm::execute(&job_id, force), cli::Command::Register { connection, name } => { commands::register::execute(&connection, name.as_deref()) diff --git a/p/src/ssh.rs b/p/src/ssh.rs index ffced7f..ef63b9d 100644 --- a/p/src/ssh.rs +++ b/p/src/ssh.rs @@ -35,8 +35,10 @@ pub fn hostname_from_connection(conn: &str) -> String { /// Check whether a worker is reachable over SSH (5 s timeout, no auth prompts). pub fn is_reachable(worker: &WorkerConfig) -> bool { let mut args = vec![ - "-o".to_string(), "ConnectTimeout=5".to_string(), - "-o".to_string(), "BatchMode=yes".to_string(), + "-o".to_string(), + "ConnectTimeout=5".to_string(), + "-o".to_string(), + "BatchMode=yes".to_string(), ]; args.extend(ssh_args(worker)); args.push("true".to_string());