Skip to content

Commit 5ed5578

Browse files
committed
introduce the util_app function to avoid duplication
1 parent 45f81bb commit 5ed5578

File tree

88 files changed

+843
-1281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+843
-1281
lines changed

src/uu/arch/src/arch.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2121
}
2222

2323
pub fn uu_app() -> Command {
24-
Command::new(uucore::util_name())
25-
.version(uucore::crate_version!())
26-
.help_template(uucore::localized_help_template(uucore::util_name()))
27-
.about(translate!("arch-about"))
28-
.after_help(translate!("arch-after-help"))
29-
.infer_long_args(true)
24+
uucore::util_app("arch").after_help(translate!("arch-after-help"))
3025
}

src/uu/basename/src/basename.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::io::{Write, stdout};
1212
use std::path::PathBuf;
1313
use uucore::display::Quotable;
1414
use uucore::error::{UResult, UUsageError};
15-
use uucore::format_usage;
1615
use uucore::line_ending::LineEnding;
1716

1817
use uucore::translate;
@@ -79,12 +78,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7978
}
8079

8180
pub fn uu_app() -> Command {
82-
Command::new(uucore::util_name())
83-
.version(uucore::crate_version!())
84-
.help_template(uucore::localized_help_template(uucore::util_name()))
85-
.about(translate!("basename-about"))
86-
.override_usage(format_usage(&translate!("basename-usage")))
87-
.infer_long_args(true)
81+
uucore::util_app("basename")
8882
.arg(
8983
Arg::new(options::MULTIPLE)
9084
.short('a')

src/uu/cat/src/cat.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use std::os::unix::net::UnixStream;
2525
use thiserror::Error;
2626
use uucore::display::Quotable;
2727
use uucore::error::UResult;
28+
use uucore::fast_inc::fast_inc_one;
2829
#[cfg(not(target_os = "windows"))]
2930
use uucore::libc;
3031
use uucore::translate;
31-
use uucore::{fast_inc::fast_inc_one, format_usage};
3232

3333
/// Linux splice support
3434
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -283,12 +283,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
283283
}
284284

285285
pub fn uu_app() -> Command {
286-
Command::new(uucore::util_name())
287-
.version(uucore::crate_version!())
288-
.override_usage(format_usage(&translate!("cat-usage")))
289-
.about(translate!("cat-about"))
290-
.help_template(uucore::localized_help_template(uucore::util_name()))
291-
.infer_long_args(true)
286+
uucore::util_app("cat")
292287
.args_override_self(true)
293288
.arg(
294289
Arg::new(options::FILE)

src/uu/chcon/src/chcon.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use clap::builder::ValueParser;
1010
use uucore::error::{UResult, USimpleError, UUsageError};
1111
use uucore::translate;
12-
use uucore::{display::Quotable, format_usage, show_error, show_warning};
12+
use uucore::{display::Quotable, show_error, show_warning};
1313

1414
use clap::{Arg, ArgAction, ArgMatches, Command};
1515
use selinux::{OpaqueSecurityContext, SecurityContext};
@@ -154,12 +154,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
154154
}
155155

156156
pub fn uu_app() -> Command {
157-
let cmd = Command::new(uucore::util_name())
158-
.version(uucore::crate_version!())
159-
.about(translate!("chcon-about"))
160-
.override_usage(format_usage(&translate!("chcon-usage")))
161-
.infer_long_args(true);
162-
uucore::clap_localization::configure_localized_command(cmd)
157+
uucore::util_app("chcon")
163158
.args_override_self(true)
164159
.disable_help_flag(true)
165160
.arg(

src/uu/chgrp/src/chgrp.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use uucore::display::Quotable;
99
use uucore::entries;
1010
use uucore::error::{FromIo, UResult, USimpleError};
11-
use uucore::format_usage;
1211
use uucore::perms::{GidUidOwnerFilter, IfFrom, chown_base, options};
1312
use uucore::translate;
1413

@@ -98,12 +97,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
9897
}
9998

10099
pub fn uu_app() -> Command {
101-
let cmd = Command::new(uucore::util_name())
102-
.version(uucore::crate_version!())
103-
.about(translate!("chgrp-about"))
104-
.override_usage(format_usage(&translate!("chgrp-usage")))
105-
.infer_long_args(true);
106-
uucore::clap_localization::configure_localized_command(cmd)
100+
uucore::util_app("chgrp")
107101
.disable_help_flag(true)
108102
.arg(
109103
Arg::new(options::HELP)

src/uu/chmod/src/chmod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use uucore::perms::{TraverseSymlinks, configure_symlink_and_recursion};
2020

2121
#[cfg(target_os = "linux")]
2222
use uucore::safe_traversal::DirFd;
23-
use uucore::{format_usage, show, show_error};
23+
use uucore::{show, show_error};
2424

2525
use uucore::translate;
2626

@@ -175,13 +175,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
175175
}
176176

177177
pub fn uu_app() -> Command {
178-
Command::new(uucore::util_name())
179-
.version(uucore::crate_version!())
180-
.about(translate!("chmod-about"))
181-
.override_usage(format_usage(&translate!("chmod-usage")))
182-
.help_template(uucore::localized_help_template(uucore::util_name()))
178+
uucore::util_app("chmod")
183179
.args_override_self(true)
184-
.infer_long_args(true)
185180
.no_binary_name(true)
186181
.disable_help_flag(true)
187182
.after_help(translate!("chmod-after-help"))

src/uu/chown/src/chown.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use uucore::display::Quotable;
99
pub use uucore::entries::{self, Group, Locate, Passwd};
10-
use uucore::format_usage;
1110
use uucore::perms::{GidUidOwnerFilter, IfFrom, chown_base, options};
1211
use uucore::translate;
1312

@@ -75,12 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7574
}
7675

7776
pub fn uu_app() -> Command {
78-
Command::new(uucore::util_name())
79-
.version(uucore::crate_version!())
80-
.help_template(uucore::localized_help_template(uucore::util_name()))
81-
.about(translate!("chown-about"))
82-
.override_usage(format_usage(&translate!("chown-usage")))
83-
.infer_long_args(true)
77+
uucore::util_app("chown")
8478
.disable_help_flag(true)
8579
.arg(
8680
Arg::new(options::HELP)

src/uu/chroot/src/chroot.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use uucore::entries::{Locate, Passwd, grp2gid, usr2uid};
1717
use uucore::error::{UResult, UUsageError, set_exit_code};
1818
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
1919
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
20-
use uucore::{format_usage, show};
20+
use uucore::show;
2121

2222
use uucore::translate;
2323

@@ -235,13 +235,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
235235
}
236236

237237
pub fn uu_app() -> Command {
238-
let cmd = Command::new(uucore::util_name())
239-
.version(uucore::crate_version!())
240-
.about(translate!("chroot-about"))
241-
.override_usage(format_usage(&translate!("chroot-usage")))
242-
.infer_long_args(true)
243-
.trailing_var_arg(true);
244-
uucore::clap_localization::configure_localized_command(cmd)
238+
uucore::util_app("chroot")
239+
.trailing_var_arg(true)
245240
.arg(
246241
Arg::new(options::NEWROOT)
247242
.value_hint(clap::ValueHint::DirPath)

src/uu/cksum/src/cksum.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use uucore::checksum::{
2222
use uucore::error::UResult;
2323
use uucore::hardware::{HasHardwareFeatures as _, SimdPolicy};
2424
use uucore::line_ending::LineEnding;
25-
use uucore::{format_usage, translate};
25+
use uucore::translate;
2626

2727
/// Print CPU hardware capability detection information to stderr
2828
/// This matches GNU cksum's --debug behavior
@@ -226,12 +226,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
226226
}
227227

228228
pub fn uu_app() -> Command {
229-
Command::new(uucore::util_name())
230-
.version(uucore::crate_version!())
231-
.help_template(uucore::localized_help_template(uucore::util_name()))
232-
.about(translate!("cksum-about"))
233-
.override_usage(format_usage(&translate!("cksum-usage")))
234-
.infer_long_args(true)
229+
uucore::util_app("cksum")
235230
.args_override_self(true)
236231
.arg(
237232
Arg::new(options::FILE)

src/uu/comm/src/comm.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::fs::{File, metadata};
1111
use std::io::{self, BufRead, BufReader, Read, StdinLock, stdin};
1212
use std::path::Path;
1313
use uucore::error::{FromIo, UResult, USimpleError};
14-
use uucore::format_usage;
1514
use uucore::fs::paths_refer_to_same_file;
1615
use uucore::line_ending::LineEnding;
1716
use uucore::translate;
@@ -340,12 +339,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
340339
}
341340

342341
pub fn uu_app() -> Command {
343-
Command::new(uucore::util_name())
344-
.version(uucore::crate_version!())
345-
.help_template(uucore::localized_help_template(uucore::util_name()))
346-
.about(translate!("comm-about"))
347-
.override_usage(format_usage(&translate!("comm-usage")))
348-
.infer_long_args(true)
342+
uucore::util_app("comm")
349343
.args_override_self(true)
350344
.arg(
351345
Arg::new(options::COLUMN_1)

0 commit comments

Comments
 (0)