use clap::{Parser, Subcommand, ValueEnum};
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
#[derive(Parser)]
#[command(version, about, long_about)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Clone, Debug, Default, ValueEnum)]
pub enum LockScope {
#[default]
WholeFile,
WholeByteRange,
}
impl Display for LockScope {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::WholeFile => write!(f, "whole-file"),
Self::WholeByteRange => write!(f, "whole-byte-range"),
}
}
}
#[derive(Debug, Subcommand)]
#[allow(clippy::enum_variant_names)]
#[non_exhaustive]
pub enum Command {
#[command(name = "write-lock")]
WriteLock {
#[arg()] file: PathBuf,
#[cfg(any(target_os = "android", target_os = "linux"))]
#[arg(long = "legacy")]
dont_use_ofd: bool,
#[arg(long = "scope", default_value_t = LockScope::default())]
scope: LockScope,
},
#[command(name = "read-lock")]
ReadLock {
#[arg()] file: PathBuf,
#[cfg(any(target_os = "android", target_os = "linux"))]
#[arg(long = "legacy")]
dont_use_ofd: bool,
#[arg(long = "scope", default_value_t = LockScope::default())]
scope: LockScope,
},
#[command(name = "test-lock")]
TestLock {
#[arg()] file: PathBuf,
#[cfg(any(target_os = "android", target_os = "linux"))]
#[arg(long = "legacy")]
dont_use_ofd: bool,
#[arg(long = "scope", default_value_t = LockScope::default())]
scope: LockScope,
},
}