use clap::Parser;
use rune_epoch::{from_utc_string, now_millis, now_secs, to_utc_string};
use std::process::ExitCode;
#[derive(Parser)]
#[command(name = "rune-epoch", version, author)]
struct Cli {
input: Option<String>,
#[arg(short, long)]
millis: bool,
}
fn main() -> ExitCode {
let cli = Cli::parse();
match cli.input {
None => {
if cli.millis {
println!("{}", now_millis());
} else {
println!("{}", now_secs());
}
}
Some(value) => {
if let Ok(epoch_secs) = value.parse::<i64>() {
println!("{}", to_utc_string(epoch_secs));
} else {
match from_utc_string(&value) {
Ok(epoch_secs) => println!("{epoch_secs}"),
Err(error) => {
eprintln!("error: {error}");
return ExitCode::FAILURE;
}
}
}
}
}
ExitCode::SUCCESS
}