2023-12-27 00:15:02 +00:00
|
|
|
#![feature(exit_status_error)]
|
2023-09-09 08:03:53 +00:00
|
|
|
#![feature(round_char_boundary)]
|
|
|
|
#![feature(exact_size_is_empty)]
|
|
|
|
use std::io::Read;
|
|
|
|
|
2023-09-12 19:15:21 +00:00
|
|
|
use organic::compare::run_anonymous_compare;
|
|
|
|
use organic::compare::run_compare_on_file;
|
2023-09-09 08:03:53 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
use crate::init_tracing::init_telemetry;
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
use crate::init_tracing::shutdown_telemetry;
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
mod init_tracing;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "tracing"))]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2023-10-14 21:43:49 +00:00
|
|
|
let rt = tokio::runtime::Runtime::new()?;
|
2023-10-16 23:12:25 +00:00
|
|
|
rt.block_on(async {
|
2023-10-14 21:43:49 +00:00
|
|
|
let main_body_result = main_body().await;
|
|
|
|
main_body_result
|
2023-10-16 23:12:25 +00:00
|
|
|
})
|
2023-09-09 08:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let rt = tokio::runtime::Runtime::new()?;
|
2023-10-16 23:12:25 +00:00
|
|
|
rt.block_on(async {
|
2023-09-09 08:03:53 +00:00
|
|
|
init_telemetry()?;
|
2023-10-14 23:20:49 +00:00
|
|
|
let main_body_result = main_body().await;
|
2023-09-09 08:03:53 +00:00
|
|
|
shutdown_telemetry()?;
|
|
|
|
main_body_result
|
2023-10-16 23:12:25 +00:00
|
|
|
})
|
2023-09-09 08:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-10-14 21:43:49 +00:00
|
|
|
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
2023-09-09 08:03:53 +00:00
|
|
|
let args = std::env::args().skip(1);
|
|
|
|
if args.is_empty() {
|
|
|
|
let org_contents = read_stdin_to_string()?;
|
2023-10-14 21:48:38 +00:00
|
|
|
if run_anonymous_compare(org_contents).await? {
|
2023-10-14 18:47:57 +00:00
|
|
|
} else {
|
|
|
|
Err("Diff results do not match.")?;
|
|
|
|
}
|
|
|
|
Ok(())
|
2023-09-09 08:03:53 +00:00
|
|
|
} else {
|
|
|
|
for arg in args {
|
2023-10-14 21:48:38 +00:00
|
|
|
if run_compare_on_file(arg).await? {
|
2023-10-14 18:47:57 +00:00
|
|
|
} else {
|
|
|
|
Err("Diff results do not match.")?;
|
|
|
|
}
|
2023-09-09 08:03:53 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
|
|
|
|
let mut stdin_contents = String::new();
|
|
|
|
std::io::stdin()
|
|
|
|
.lock()
|
|
|
|
.read_to_string(&mut stdin_contents)?;
|
|
|
|
Ok(stdin_contents)
|
|
|
|
}
|