command : la struct UnixProgram contient désormais un std::process::Command construit à son initialisation à partir d'un argv

This commit is contained in:
Ahurac 2024-04-11 01:35:16 +02:00
parent 2a0f11cca8
commit d7f2de803d

View file

@ -49,20 +49,12 @@ impl Command for CommandSequence {
} }
pub struct UnixProgram { pub struct UnixProgram {
argv: Vec<String>, command: std::process::Command,
} }
impl UnixProgram { impl UnixProgram {
pub fn new(argv: Vec<String>) -> Self { pub fn new(mut argv: Vec<String>) -> Self {
Self { argv }
}
}
impl Command for UnixProgram {
fn spawn(&self) -> ExitCode {
let mut argv = self.argv.clone();
let program = argv.remove(0); let program = argv.remove(0);
let mut command = std::process::Command::new(&program); let mut command = std::process::Command::new(&program);
command.args(argv); command.args(argv);
@ -89,7 +81,10 @@ impl Command for UnixProgram {
exit_code exit_code
} else { } else {
let message = format!("{}: command not found", &program); let message = format!(
"{}: command not found",
self.command.get_program().to_str().unwrap()
);
error::print_error(message); error::print_error(message);
ExitCode::not_found() ExitCode::not_found()
} }