Skip to content

Commit a2973a6

Browse files
authored
Merge pull request #307 from Byron/copilot/mark-global-arguments-in-clap
Mark shared arguments as global in clap
2 parents 8570c15 + 2f720cf commit a2973a6

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/main.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ fn main() -> Result<()> {
5959
walk_options.threads = num_cpus::get();
6060
}
6161

62+
let cross_filesystems = walk_options.cross_filesystems;
63+
6264
let res = match opt.command {
6365
#[cfg(feature = "tui-crossplatform")]
64-
Some(Interactive {
65-
no_entry_check,
66-
input,
67-
}) => {
66+
Some(Interactive { no_entry_check }) => {
6867
use anyhow::{Context, anyhow};
6968
use crosstermion::terminal::{AlternateRawScreen, tui::new_terminal};
7069

@@ -84,7 +83,7 @@ fn main() -> Result<()> {
8483
walk_options,
8584
byte_format,
8685
!no_entry_check,
87-
extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
86+
extract_paths_maybe_set_cwd(opt.input, cross_filesystems)?,
8887
)?;
8988
app.traverse()?;
9089

@@ -120,7 +119,6 @@ fn main() -> Result<()> {
120119
);
121120
}
122121
Some(Aggregate {
123-
input,
124122
no_total,
125123
no_sort,
126124
statistics,
@@ -134,7 +132,7 @@ fn main() -> Result<()> {
134132
!no_total,
135133
!no_sort,
136134
byte_format,
137-
extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
135+
extract_paths_maybe_set_cwd(opt.input, cross_filesystems)?,
138136
)?;
139137
if statistics {
140138
writeln!(io::stderr(), "{stats:?}").ok();
@@ -157,7 +155,7 @@ fn main() -> Result<()> {
157155
true,
158156
true,
159157
byte_format,
160-
extract_paths_maybe_set_cwd(opt.input, !opt.stay_on_filesystem)?,
158+
extract_paths_maybe_set_cwd(opt.input, cross_filesystems)?,
161159
)?
162160
.0
163161
}

src/options.rs

Lines changed: 8 additions & 13 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)]
56+
#[clap(short = 't', long = "threads", default_value_t = DEFAULT_THREADS, global = true)]
5757
pub threads: usize,
5858

5959
/// The format with which to print byte counts.
@@ -63,34 +63,35 @@ pub struct Args {
6363
value_enum,
6464
default_value_t = dft_format(),
6565
ignore_case = true,
66+
global = true,
6667
)]
6768
pub format: ByteFormat,
6869

6970
/// Display apparent size instead of disk usage.
70-
#[clap(short = 'A', long)]
71+
#[clap(short = 'A', long, global = true)]
7172
pub apparent_size: bool,
7273

7374
/// Count hard-linked files each time they are seen
74-
#[clap(short = 'l', long)]
75+
#[clap(short = 'l', long, global = true)]
7576
pub count_hard_links: bool,
7677

7778
/// If set, we will not cross filesystems or traverse mount points
78-
#[clap(short = 'x', long)]
79+
#[clap(short = 'x', long, global = true)]
7980
pub stay_on_filesystem: bool,
8081

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

8889
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
89-
#[clap(value_parser)]
90+
#[clap(value_parser, global = true)]
9091
pub input: Vec<PathBuf>,
9192

9293
/// Write a log file with debug information, including panics.
93-
#[clap(long)]
94+
#[clap(long, global = true)]
9495
pub log_file: Option<PathBuf>,
9596
}
9697

@@ -103,9 +104,6 @@ pub enum Command {
103104
/// Do not check entries for presence when listing a directory to avoid slugging performance on slow filesystems.
104105
#[clap(long, short = 'e')]
105106
no_entry_check: bool,
106-
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
107-
#[clap(value_parser)]
108-
input: Vec<PathBuf>,
109107
},
110108
/// Aggregate the consumed space of one or more directories or files
111109
#[clap(name = "aggregate", visible_alias = "a")]
@@ -120,9 +118,6 @@ pub enum Command {
120118
/// If set, no total column will be computed for multiple inputs
121119
#[clap(long)]
122120
no_total: bool,
123-
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
124-
#[clap(value_parser)]
125-
input: Vec<PathBuf>,
126121
},
127122
/// Generate shell completions
128123
Completions {

0 commit comments

Comments
 (0)