use {
clap::{
Parser,
ValueEnum,
},
std::{
path::PathBuf,
str::FromStr,
},
};
#[derive(Debug, Parser)]
#[command(about, version, disable_version_flag = true, disable_help_flag = true)]
pub struct Args {
#[arg(long)]
pub help: bool,
#[arg(long)]
pub version: bool,
#[arg(long, value_name = "paths")]
pub conf: Option<String>,
#[arg(short, long)]
pub dates: bool,
#[arg(short = 'D', long)]
pub no_dates: bool,
#[arg(short = 'f', long)]
pub only_folders: bool,
#[arg(short = 'F', long)]
pub no_only_folders: bool,
#[arg(long)]
pub show_root_fs: bool,
#[arg(long)]
pub max_depth: Option<u16>,
#[arg(short = 'g', long)]
pub show_git_info: bool,
#[arg(short = 'G', long)]
pub no_show_git_info: bool,
#[arg(long)]
pub git_status: bool,
#[arg(short = 'h', long)]
pub hidden: bool,
#[arg(short = 'H', long)]
pub no_hidden: bool,
#[arg(short = 'i', long)]
pub git_ignored: bool,
#[arg(short = 'I', long)]
pub no_git_ignored: bool,
#[arg(short = 'p', long)]
pub permissions: bool,
#[arg(short = 'P', long)]
pub no_permissions: bool,
#[arg(short = 's', long)]
pub sizes: bool,
#[arg(short = 'S', long)]
pub no_sizes: bool,
#[arg(long)]
pub sort_by_count: bool,
#[arg(long)]
pub sort_by_date: bool,
#[arg(long)]
pub sort_by_size: bool,
#[arg(long)]
pub sort_by_type: bool,
#[arg(long)]
pub no_tree: bool,
#[arg(long)]
pub tree: bool,
#[arg(long)]
pub sort_by_type_dirs_first: bool,
#[arg(long)]
pub sort_by_type_dirs_last: bool,
#[arg(long)]
pub no_sort: bool,
#[arg(short, long)]
pub whale_spotting: bool,
#[arg(short = 'W', long)]
pub no_whale_spotting: bool,
#[arg(short = 't', long)]
pub trim_root: bool,
#[arg(short = 'T', long)]
pub no_trim_root: bool,
#[arg(long, value_name = "path")]
pub outcmd: Option<PathBuf>,
#[arg(long, value_name = "verb-output")]
pub verb_output: Option<PathBuf>,
#[arg(short, long, value_name = "cmd")]
pub cmd: Option<String>,
#[arg(long, default_value = "auto", value_name = "color")]
pub color: TriBool,
#[arg(long, value_name = "height")]
pub height: Option<u16>,
#[arg(long)]
pub install: bool,
#[arg(long, value_name = "state")]
pub set_install_state: Option<CliShellInstallState>,
#[arg(long, value_name = "shell")]
pub print_shell_function: Option<String>,
#[cfg(unix)]
#[arg(long, value_name = "socket")]
pub listen: Option<String>,
#[cfg(unix)]
#[arg(long)]
pub listen_auto: bool,
#[cfg(unix)]
#[arg(long)]
pub get_root: bool,
#[arg(long, value_name = "path")]
pub write_default_conf: Option<PathBuf>,
#[cfg(unix)]
#[arg(long, value_name = "socket")]
pub send: Option<String>,
pub root: Option<PathBuf>,
}
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum TriBool {
Auto,
Yes,
No,
}
impl TriBool {
pub fn unwrap_or_else<F>(
self,
f: F,
) -> bool
where
F: FnOnce() -> bool,
{
match self {
Self::Auto => f(),
Self::Yes => true,
Self::No => false,
}
}
}
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum CliShellInstallState {
Undefined, Refused,
Installed,
}
impl FromStr for CliShellInstallState {
type Err = String;
fn from_str(state: &str) -> Result<Self, Self::Err> {
match state {
"undefined" => Ok(Self::Undefined),
"refused" => Ok(Self::Refused),
"installed" => Ok(Self::Installed),
_ => Err(format!("unexpected install state: {state:?}")),
}
}
}