use clap_complete::Shell;
use dua::ByteFormat as LibraryByteFormat;
use std::path::PathBuf;
#[derive(PartialEq, Eq, Debug, Clone, Copy, clap::ValueEnum)]
pub enum ByteFormat {
Metric,
Binary,
Bytes,
GB,
Gib,
MB,
Mib,
}
impl From<ByteFormat> for LibraryByteFormat {
fn from(input: ByteFormat) -> Self {
match input {
ByteFormat::Metric => LibraryByteFormat::Metric,
ByteFormat::Binary => LibraryByteFormat::Binary,
ByteFormat::Bytes => LibraryByteFormat::Bytes,
ByteFormat::GB => LibraryByteFormat::GB,
ByteFormat::Gib => LibraryByteFormat::GiB,
ByteFormat::MB => LibraryByteFormat::MB,
ByteFormat::Mib => LibraryByteFormat::MiB,
}
}
}
fn dft_format() -> ByteFormat {
if cfg!(target_vendor = "apple") {
ByteFormat::Metric
} else {
ByteFormat::Binary
}
}
#[cfg(target_os = "macos")]
const DEFAULT_THREADS: usize = 3;
#[cfg(not(target_os = "macos"))]
const DEFAULT_THREADS: usize = 0;
#[derive(Debug, clap::Parser)]
#[clap(name = "dua", version)]
#[clap(override_usage = "dua [FLAGS] [OPTIONS] [SUBCOMMAND] [INPUT]...")]
pub struct Args {
#[clap(subcommand)]
pub command: Option<Command>,
#[clap(short = 't', long = "threads", default_value_t = DEFAULT_THREADS, global = true, env = "DUA_THREADS")]
pub threads: usize,
#[clap(
short = 'f',
long,
value_enum,
default_value_t = dft_format(),
ignore_case = true,
global = true,
env = "DUA_FORMAT",
)]
pub format: ByteFormat,
#[clap(short = 'A', long, global = true, env = "DUA_APPARENT_SIZE")]
pub apparent_size: bool,
#[clap(short = 'l', long, global = true, env = "DUA_COUNT_HARD_LINKS")]
pub count_hard_links: bool,
#[clap(short = 'x', long, global = true, env = "DUA_STAY_ON_FILESYSTEM")]
pub stay_on_filesystem: bool,
#[clap(
long = "ignore-dirs",
short = 'i',
value_parser,
global = true,
env = "DUA_IGNORE_DIRS"
)]
#[cfg_attr(target_os = "linux", clap(default_values = &["/proc", "/dev", "/sys", "/run"]))]
pub ignore_dirs: Vec<PathBuf>,
#[clap(value_parser, global = true)]
pub input: Vec<PathBuf>,
#[clap(long, global = true, env = "DUA_LOG_FILE")]
pub log_file: Option<PathBuf>,
}
#[derive(Debug, clap::Subcommand)]
pub enum Command {
#[cfg(feature = "tui-crossplatform")]
#[clap(name = "interactive", visible_alias = "i")]
Interactive {
#[clap(long, short = 'e')]
no_entry_check: bool,
},
#[clap(name = "aggregate", visible_alias = "a")]
Aggregate {
#[clap(long = "stats")]
statistics: bool,
#[clap(long)]
no_sort: bool,
#[clap(long)]
no_total: bool,
},
Completions {
shell: Shell,
},
Config {
#[clap(subcommand)]
command: ConfigCommand,
},
}
#[derive(Debug, clap::Subcommand)]
pub enum ConfigCommand {
Edit,
}