-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update module imports and file paths for scimon integration
- Loading branch information
Showing
4 changed files
with
66 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod pdf; | ||
pub mod system; | ||
pub mod hashes; | ||
pub mod scripts; | ||
pub mod markdown; | ||
pub mod providers; | ||
pub mod reporting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
extern crate chrono; | ||
|
||
use regex::Regex; | ||
|
||
use std::{ | ||
error::Error, | ||
|
||
process::{ | ||
Stdio, | ||
Command, | ||
}, | ||
}; | ||
|
||
use crate::{ | ||
regexp::regex_core::CoreRegExp, | ||
ui::errors_commands_alerts::ErrorsCommandsAlerts, | ||
}; | ||
|
||
pub struct Scripts; | ||
|
||
impl Scripts { | ||
|
||
pub fn exec(line: &str, program: &str) -> Result<(), Box<dyn Error>> { | ||
let line_cleanned = Regex::new( | ||
CoreRegExp::CLEAN_LINE | ||
).unwrap().replace_all( | ||
&line, "" | ||
).to_string(); | ||
|
||
let output = Command::new(&program) | ||
.arg(line_cleanned) | ||
.stdout(Stdio::piped()) | ||
.output()?; | ||
|
||
if output.status.success() { | ||
let stdout = String::from_utf8_lossy(&output.stdout); | ||
println!("{}", stdout); | ||
} else { | ||
let stderr = String::from_utf8_lossy(&output.stderr); | ||
ErrorsCommandsAlerts::executing(&stderr); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn read(line_trimmed: &str) -> Result<(), Box<dyn Error>> { | ||
if line_trimmed.len() >= 3 { | ||
if line_trimmed.ends_with(".py") { | ||
Self::exec(&line_trimmed, "python")?; | ||
} else if line_trimmed.ends_with(".js") { | ||
Self::exec(&line_trimmed, "node")?; | ||
} else { | ||
ErrorsCommandsAlerts::unsupported(&line_trimmed); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters