use chrono::prelude::*;
use clap::Parser;
#[derive(Parser)]
#[command(
name = "timestamp-cli",
version = "0.1.0",
author = "Rashid Rasul",
about = "Generate a timestamp with an optional offset"
)]
struct Cli {
#[arg(default_value_t = 0)]
seconds: i64,
#[arg(long, default_value = "default")]
format: String,
}
fn main() {
let cli = Cli::parse();
let now = Local::now();
let target = now + chrono::Duration::seconds(cli.seconds);
let output = match cli.format.to_lowercase().as_str() {
"rfc3339" => target.to_rfc3339_opts(SecondsFormat::Secs, true),
"default" => target.format("%Y-%m-%d %H:%M:%S").to_string(),
other => {
eprintln!("Error: Unsupported format '{}'", other);
std::process::exit(1);
}
};
println!("{}", output);
}