2020-01-16 09:05:53 +00:00
|
|
|
pub mod commands;
|
2019-12-15 16:15:06 +00:00
|
|
|
pub mod fs;
|
|
|
|
pub mod macros;
|
|
|
|
pub mod playground;
|
|
|
|
|
2021-02-19 01:24:27 +00:00
|
|
|
pub struct Outcome {
|
|
|
|
pub out: String,
|
|
|
|
pub err: String,
|
|
|
|
}
|
|
|
|
|
2021-07-23 14:03:28 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
pub const NATIVE_PATH_ENV_VAR: &str = "Path";
|
|
|
|
#[cfg(not(windows))]
|
2021-05-13 03:03:49 +00:00
|
|
|
pub const NATIVE_PATH_ENV_VAR: &str = "PATH";
|
|
|
|
|
2021-06-25 03:58:37 +00:00
|
|
|
#[cfg(windows)]
|
2021-07-23 14:03:28 +00:00
|
|
|
pub const NATIVE_PATH_ENV_SEPARATOR: char = ';';
|
2021-07-24 13:42:50 +00:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
pub const NATIVE_PATH_ENV_SEPARATOR: char = ':';
|
2021-06-25 03:58:37 +00:00
|
|
|
|
2021-02-19 01:24:27 +00:00
|
|
|
impl Outcome {
|
|
|
|
pub fn new(out: String, err: String) -> Outcome {
|
|
|
|
Outcome { out, err }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 16:15:06 +00:00
|
|
|
pub fn pipeline(commands: &str) -> String {
|
|
|
|
commands
|
2022-02-17 22:23:04 +00:00
|
|
|
.trim()
|
2019-12-15 16:15:06 +00:00
|
|
|
.lines()
|
|
|
|
.map(|line| line.trim())
|
|
|
|
.collect::<Vec<&str>>()
|
|
|
|
.join(" ")
|
|
|
|
.trim_end()
|
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:21:05 +00:00
|
|
|
pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
|
|
|
|
let mut original_paths = vec![];
|
|
|
|
|
2021-05-13 03:03:49 +00:00
|
|
|
if let Some(paths) = std::env::var_os(NATIVE_PATH_ENV_VAR) {
|
2020-01-23 16:21:05 +00:00
|
|
|
original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
original_paths
|
|
|
|
}
|
|
|
|
|
2020-01-12 21:44:22 +00:00
|
|
|
#[cfg(test)]
|
2019-12-15 16:15:06 +00:00
|
|
|
mod tests {
|
|
|
|
use super::pipeline;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn constructs_a_pipeline() {
|
|
|
|
let actual = pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_amigos.txt
|
|
|
|
| from-csv
|
|
|
|
| get rusty_luck
|
2022-02-04 02:01:45 +00:00
|
|
|
| into int
|
2020-06-19 02:02:01 +00:00
|
|
|
| math sum
|
2019-12-15 16:15:06 +00:00
|
|
|
| echo "$it"
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual,
|
2022-02-04 02:01:45 +00:00
|
|
|
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | into int | math sum | echo "$it""#
|
2019-12-15 16:15:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|