Skip to content

Commit 72f149c

Browse files
authored
Merge pull request #309 from Byron/copilot/add-env-support-global-arguments
Add environment variable support for global arguments
2 parents a2973a6 + 85c7c72 commit 72f149c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tui-crossplatform = [
2929
trash-move = ["trash"]
3030

3131
[dependencies]
32-
clap = { version = "4.0.29", features = ["derive"] }
32+
clap = { version = "4.0.29", features = ["derive", "env"] }
3333
clap_complete = "4.5.54"
3434
jwalk = "0.8.1"
3535
byte-unit = "4"

src/options.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Args {
5353

5454
/// The amount of threads to use. Defaults to 0, indicating the amount of logical processors.
5555
/// Set to 1 to use only a single thread.
56-
#[clap(short = 't', long = "threads", default_value_t = DEFAULT_THREADS, global = true)]
56+
#[clap(short = 't', long = "threads", default_value_t = DEFAULT_THREADS, global = true, env = "DUA_THREADS")]
5757
pub threads: usize,
5858

5959
/// The format with which to print byte counts.
@@ -64,25 +64,26 @@ pub struct Args {
6464
default_value_t = dft_format(),
6565
ignore_case = true,
6666
global = true,
67+
env = "DUA_FORMAT",
6768
)]
6869
pub format: ByteFormat,
6970

7071
/// Display apparent size instead of disk usage.
71-
#[clap(short = 'A', long, global = true)]
72+
#[clap(short = 'A', long, global = true, env = "DUA_APPARENT_SIZE")]
7273
pub apparent_size: bool,
7374

7475
/// Count hard-linked files each time they are seen
75-
#[clap(short = 'l', long, global = true)]
76+
#[clap(short = 'l', long, global = true, env = "DUA_COUNT_HARD_LINKS")]
7677
pub count_hard_links: bool,
7778

7879
/// If set, we will not cross filesystems or traverse mount points
79-
#[clap(short = 'x', long, global = true)]
80+
#[clap(short = 'x', long, global = true, env = "DUA_STAY_ON_FILESYSTEM")]
8081
pub stay_on_filesystem: bool,
8182

8283
/// One or more absolute directories to ignore. Note that these are not ignored if they are passed as input path.
8384
///
8485
/// Hence, they will only be ignored if they are eventually reached as part of the traversal.
85-
#[clap(long = "ignore-dirs", short = 'i', value_parser, global = true)]
86+
#[clap(long = "ignore-dirs", short = 'i', value_parser, global = true, env = "DUA_IGNORE_DIRS")]
8687
#[cfg_attr(target_os = "linux", clap(default_values = &["/proc", "/dev", "/sys", "/run"]))]
8788
pub ignore_dirs: Vec<PathBuf>,
8889

@@ -91,7 +92,7 @@ pub struct Args {
9192
pub input: Vec<PathBuf>,
9293

9394
/// Write a log file with debug information, including panics.
94-
#[clap(long, global = true)]
95+
#[clap(long, global = true, env = "DUA_LOG_FILE")]
9596
pub log_file: Option<PathBuf>,
9697
}
9798

0 commit comments

Comments
 (0)