mirror of
https://github.com/moghtech/komodo.git
synced 2026-09-04 16:00:59 +00:00
ea5506c202
* 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
51 lines
1.2 KiB
Rust
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(),
|
|
}
|
|
}
|