app: detect CLI availability and add command palette copy action

This commit is contained in:
Gregory Schier
2026-03-02 14:55:04 -08:00
parent cc0d31fdbb
commit 851f12f149
5 changed files with 66 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
use std::ffi::OsStr;
use std::ffi::{OsStr, OsString};
use std::io::{self, ErrorKind};
use std::process::Stdio;
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
@@ -14,3 +16,27 @@ pub fn new_xplatform_command<S: AsRef<OsStr>>(program: S) -> tokio::process::Com
}
cmd
}
/// Creates a command only if the binary exists and can be invoked with the given probe argument.
pub async fn new_checked_command<S: AsRef<OsStr>>(
program: S,
probe_arg: &str,
) -> io::Result<tokio::process::Command> {
let program: OsString = program.as_ref().to_os_string();
let mut probe = new_xplatform_command(&program);
probe.arg(probe_arg).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
let status = probe.status().await?;
if !status.success() {
return Err(io::Error::new(
ErrorKind::NotFound,
format!(
"'{}' is not available on PATH or failed to execute",
program.to_string_lossy()
),
));
}
Ok(new_xplatform_command(&program))
}