Files
komodo/lib/command/src/lib.rs
T
Maxwell Becker ea5506c202 1.16.1 (#143)
* ensure sync state cache is refreshed on sync create / copy

* clean up resources post_create

* show sidebar if element length > 1

* update `run_komodo_command` command

* rename all resources

* refresh repo cache after clone / pull

* improve rename repo log
2024-10-21 23:19:40 -07:00

51 lines
1.2 KiB
Rust

use std::path::Path;
use komodo_client::{
entities::{komodo_timestamp, update::Log},
parsers::parse_multiline_command,
};
use run_command::{async_run_command, CommandOutput};
/// If `parse_multiline: true`, parses commands out of multiline string
/// and chains them together with '&&'.
/// Supports full line and end of line comments.
/// See [parse_multiline_command].
pub async fn run_komodo_command(
stage: &str,
path: impl Into<Option<&Path>>,
command: impl AsRef<str>,
parse_multiline: bool,
) -> Log {
let command = if parse_multiline {
parse_multiline_command(command)
} else {
command.as_ref().to_string()
};
let command = if let Some(path) = path.into() {
format!("cd {} && {command}", path.display(),)
} else {
command
};
let start_ts = komodo_timestamp();
let output = async_run_command(&command).await;
output_into_log(stage, command, start_ts, output)
}
pub fn output_into_log(
stage: &str,
command: String,
start_ts: i64,
output: CommandOutput,
) -> Log {
let success = output.success();
Log {
stage: stage.to_string(),
stdout: output.stdout,
stderr: output.stderr,
command,
success,
start_ts,
end_ts: komodo_timestamp(),
}
}