#![allow(clippy::let_and_return, clippy::let_unit_value)]
use std::env::args_os;
use std::ffi::OsString;
use std::io::stdout;
use std::io::Write as _;
use std::os::unix::ffi::OsStrExt as _;
use std::path::PathBuf;
use anyhow::Result;
use clap::error::ErrorKind;
use clap::Parser;
use batch_renamer::rename;
#[derive(Debug, Parser)]
struct Args {
#[clap(short = 'n', long = "dry-run")]
dry_run: bool,
#[clap(required = true)]
command: Vec<OsString>,
file: PathBuf,
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let args = match Args::try_parse_from(args_os()) {
Ok(args) => args,
Err(err) => match err.kind() {
ErrorKind::DisplayHelp | ErrorKind::DisplayVersion => {
print!("{}", err);
return Ok(())
},
_ => return Err(err.into()),
},
};
let new_path = rename(&args.file, &args.command, args.dry_run).await?;
let () = stdout().write_all(new_path.as_os_str().as_bytes())?;
Ok(())
}