comtrya icon indicating copy to clipboard operation
comtrya copied to clipboard

Replace hard coded paths using which

Open martintc opened this issue 3 years ago • 0 comments

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()
}

martintc avatar Jul 25 '22 19:07 martintc