comtrya
comtrya copied to clipboard
Replace hard coded paths using which
In some areas of comtrya where calls are being made to echo or package managers, hard coded paths are used. A good refactor is to make use use of which at the top of functions to get the cli command. Sowing an example from some of icepuma's code.
Replacing code blocks like this
atom: Box::new(Exec {
command: String::from("zypper"),
arguments: vec![String::from("install"), String::from("-y")]
.into_iter()
.chain(package.extra_args.clone())
.chain(package.packages())
.collect(),
privileged: true,
..Default::default()
to having
pub fn some_function(....) -> .... {
let command = match which("command_name") {
Ok(c) => c,
Err(e) => //some action,
};
// ........
atom: Box::new(Exec {
command: command,
arguments: vec![String::from("install"), String::from("-y")]
.into_iter()
.chain(package.extra_args.clone())
.chain(package.packages())
.collect(),
privileged: true,
..Default::default()
}