65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
#![feature(round_char_boundary)]
|
|
#![feature(exact_size_is_empty)]
|
|
use std::io::Read;
|
|
|
|
use organic::compare::run_anonymous_compare;
|
|
use organic::compare::run_compare_on_file;
|
|
|
|
#[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>> {
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
let result = rt.block_on(async {
|
|
let main_body_result = main_body().await;
|
|
main_body_result
|
|
});
|
|
result
|
|
}
|
|
|
|
#[cfg(feature = "tracing")]
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
let result = rt.block_on(async {
|
|
init_telemetry()?;
|
|
let main_body_result = main_body().await;
|
|
shutdown_telemetry()?;
|
|
main_body_result
|
|
});
|
|
result
|
|
}
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
|
let args = std::env::args().skip(1);
|
|
if args.is_empty() {
|
|
let org_contents = read_stdin_to_string()?;
|
|
if run_anonymous_compare(org_contents).await? {
|
|
} else {
|
|
Err("Diff results do not match.")?;
|
|
}
|
|
Ok(())
|
|
} else {
|
|
for arg in args {
|
|
if run_compare_on_file(arg).await? {
|
|
} else {
|
|
Err("Diff results do not match.")?;
|
|
}
|
|
}
|
|
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)
|
|
}
|