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