mirror of
https://github.com/starship/starship.git
synced 2026-06-24 02:01:36 +07:00
refactor: allow passing OsStr as-is to exec_cmd (#2997)
This commit is contained in:
+9
-7
@@ -9,7 +9,8 @@ use git2::{ErrorCode::UnbornBranch, Repository, RepositoryState};
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fmt::Debug;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::string::String;
|
||||
@@ -266,18 +267,19 @@ impl<'a> Context<'a> {
|
||||
|
||||
/// Execute a command and return the output on stdout and stderr if successful
|
||||
#[inline]
|
||||
pub fn exec_cmd(&self, cmd: &str, args: &[&str]) -> Option<CommandOutput> {
|
||||
pub fn exec_cmd<T: AsRef<OsStr> + Debug, U: AsRef<OsStr> + Debug>(
|
||||
&self,
|
||||
cmd: T,
|
||||
args: &[U],
|
||||
) -> Option<CommandOutput> {
|
||||
#[cfg(test)]
|
||||
{
|
||||
let command = match args.len() {
|
||||
0 => cmd.to_owned(),
|
||||
_ => format!("{} {}", cmd, args.join(" ")),
|
||||
};
|
||||
let command = crate::utils::display_command(&cmd, args);
|
||||
if let Some(output) = self.cmd.get(command.as_str()) {
|
||||
return output.clone();
|
||||
}
|
||||
}
|
||||
exec_cmd(cmd, args, self.cmd_timeout)
|
||||
exec_cmd(&cmd, args, self.cmd_timeout)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user