diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a2aa9..da45d05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - "Encrypting with Sops" documentation example. +- `--ssh-verbose` / `--sv` argument which increases verbosity of SSH commands. ### Changed diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 5e558ee..235a838 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -2,7 +2,7 @@ // Copyright 2024-2025 wire Contributors use clap::builder::PossibleValue; -use clap::{Args, Parser, Subcommand, ValueEnum}; +use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum}; use clap::{ValueHint, crate_version}; use clap_complete::CompletionCandidate; use clap_complete::engine::ArgValueCompleter; @@ -213,6 +213,10 @@ pub struct ApplyArgs { /// Vulnerable to man-in-the-middle attacks, use with caution. #[arg(long, default_value_t = false)] pub ssh_accept_host: bool, + + /// Increase debug verbosity of SSH commands. + #[arg(long, visible_alias = "sv", action = ArgAction::Count, default_value_t = 0, value_parser=less_than_3)] + pub ssh_verbose: u8, } #[derive(Clone, Debug)] @@ -332,6 +336,10 @@ impl ToSubCommandModifiers for Cli { } _ => wire_core::StrictHostKeyChecking::default(), }, + ssh_verbosity: match &self.command { + Commands::Apply(args) => args.ssh_verbose.into(), + _ => 0, + }, } } } @@ -381,6 +389,10 @@ fn node_names_completer(current: &std::ffi::OsStr) -> Vec { }) } +fn less_than_3(s: &str) -> Result { + number_range(s, 0, 3) +} + #[cfg(test)] mod tests { use std::assert_matches::assert_matches; diff --git a/crates/core/src/commands/pty/output.rs b/crates/core/src/commands/pty/output.rs index 74407da..3aa0d27 100644 --- a/crates/core/src/commands/pty/output.rs +++ b/crates/core/src/commands/pty/output.rs @@ -221,43 +221,59 @@ fn search_string( status_sender: &watch::Sender, began_tx: &mut Option>, ) -> SearchFindings { - let searched = aho_corasick - .find_iter(haystack) - .map(|x| x.pattern()) - .collect::>(); - - let started = if searched.contains(&STARTED_PATTERN) { - debug!("start needle was found, switching mode..."); - if let Some(began_tx) = began_tx.take() { - let _ = began_tx.send(()); + for haystack in haystack.split(|&b| b == b'\n') { + if haystack.starts_with(b"debug") || haystack.starts_with(b"ssh") { + tracing::log::log!( + if haystack.starts_with(b"ssh") { + tracing::log::Level::Error + } else { + tracing::log::Level::Debug + }, + "{}", + String::from_utf8_lossy(haystack) + ); + + continue; } - true - } else { - false - }; - - let succeeded = if searched.contains(&SUCCEEDED_PATTERN) { - debug!("succeed needle was found, marking child as succeeding."); - status_sender.send_replace(Status::Done { success: true }); - true - } else { - false - }; - - let failed = if searched.contains(&FAILED_PATTERN) { - debug!("failed needle was found, elevated child did not succeed."); - status_sender.send_replace(Status::Done { success: false }); - true - } else { - false - }; - if succeeded || failed { - return SearchFindings::Terminate; - } + let searched = aho_corasick + .find_iter(haystack) + .map(|x| x.pattern()) + .collect::>(); + + let started = if searched.contains(&STARTED_PATTERN) { + debug!("start needle was found, switching mode..."); + if let Some(began_tx) = began_tx.take() { + let _ = began_tx.send(()); + } + true + } else { + false + }; + + let succeeded = if searched.contains(&SUCCEEDED_PATTERN) { + debug!("succeed needle was found, marking child as succeeding."); + status_sender.send_replace(Status::Done { success: true }); + true + } else { + false + }; + + let failed = if searched.contains(&FAILED_PATTERN) { + debug!("failed needle was found, elevated child did not succeed."); + status_sender.send_replace(Status::Done { success: false }); + true + } else { + false + }; + + if succeeded || failed { + return SearchFindings::Terminate; + } - if started { - return SearchFindings::Started; + if started { + return SearchFindings::Started; + } } SearchFindings::None diff --git a/crates/core/src/hive/node.rs b/crates/core/src/hive/node.rs index c4d90fc..65e21fe 100644 --- a/crates/core/src/hive/node.rs +++ b/crates/core/src/hive/node.rs @@ -94,6 +94,10 @@ impl Target { vector.push("-o".to_string()); vector.extend(options.into_iter().intersperse("-o".to_string())); + if modifiers.ssh_verbosity > 0 { + vector.push(format!("-{}", "v".repeat(modifiers.ssh_verbosity))); + } + Ok(vector) } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index a1b43a4..9aaf23c 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -44,6 +44,7 @@ pub struct SubCommandModifiers { pub show_trace: bool, pub non_interactive: bool, pub ssh_accept_host: StrictHostKeyChecking, + pub ssh_verbosity: usize, } impl Default for SubCommandModifiers { @@ -52,6 +53,7 @@ impl Default for SubCommandModifiers { show_trace: false, non_interactive: !std::io::stdin().is_terminal(), ssh_accept_host: StrictHostKeyChecking::default(), + ssh_verbosity: 0, } } }