Skip to content

Commit

Permalink
refactor: Update bin name in Scripts module to handle different opera…
Browse files Browse the repository at this point in the history
…ting systems
  • Loading branch information
Kremilly committed Jul 8, 2024
1 parent 9555dea commit c5e0bfe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/system/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ impl General {
format!("{} {}", date_formated, hour_formated)
}

pub fn detect_os() -> String {
std::env::consts::OS.to_string()
}

}
19 changes: 18 additions & 1 deletion src/system/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{

use crate::{
consts::folders::Folders,
system::general::General,
regexp::regex_core::CoreRegExp,
ui::errors_commands_alerts::ErrorsCommandsAlerts,

Expand All @@ -29,6 +30,20 @@ pub struct Scripts;

impl Scripts {

fn get_bin_name(name: &str) -> String {
let os = General::detect_os();

if name == "python" {
if os == "windows" {
"python".to_string()
} else {
"python3".to_string()
}
} else {
name.to_string()
}
}

pub async fn download(url: &str, path: &str) -> Result<String, Box<dyn Error>> {
let response = reqwest::get(url).await?;

Expand All @@ -50,13 +65,15 @@ impl Scripts {
}

pub fn exec(line: &str, program: &str) -> Result<(), Box<dyn Error>> {
let language = Self::get_bin_name(program);

let line_cleanned = Regex::new(
CoreRegExp::CLEAN_LINE
).unwrap().replace_all(
&line, ""
).to_string();

let output = Command::new(&program)
let output = Command::new(&language)
.arg(line_cleanned)
.stdout(Stdio::piped())
.output()?;
Expand Down

0 comments on commit c5e0bfe

Please sign in to comment.