1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

all: add format_usage function (#3139)

This should correct the usage strings in both the `--help` and user documentation. Previously, sometimes the name of the utils did not show up correctly.
This commit is contained in:
Terts Diepraam 2022-02-21 17:14:03 +01:00 committed by GitHub
parent cd450cc591
commit 53070141c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
90 changed files with 416 additions and 655 deletions

View file

@ -94,7 +94,7 @@ fn write_usage(w: &mut impl Write, app: &mut App, name: &str) -> io::Result<()>
.filter(|l| !l.is_empty()) .filter(|l| !l.is_empty())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
usage = usage.replace(app.get_name(), name); usage = usage.replace(uucore::execution_phrase(), name);
writeln!(w, "{}", usage)?; writeln!(w, "{}", usage)?;
writeln!(w, "```") writeln!(w, "```")
} }

View file

@ -22,16 +22,13 @@ to attempt to recover from any other non-alphabet bytes in the
encoded stream. encoded stream.
"; ";
fn usage() -> String { const USAGE: &str = "{} [OPTION]... [FILE]";
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let format = Format::Base32; let format = Format::Base32;
let usage = usage();
let config: base_common::Config = base_common::parse_base_cmd_args(args, ABOUT, &usage)?; let config: base_common::Config = base_common::parse_base_cmd_args(args, ABOUT, USAGE)?;
// Create a reference to stdin so we can return a locked stdin from // Create a reference to stdin so we can return a locked stdin from
// parse_base_cmd_args // parse_base_cmd_args
@ -48,5 +45,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
base_common::base_app(ABOUT) base_common::base_app(ABOUT, USAGE)
} }

View file

@ -12,7 +12,7 @@ use std::io::{stdout, Read, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::encoding::{wrap_print, Data, Format}; use uucore::encoding::{wrap_print, Data, Format};
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
use std::fs::File; use std::fs::File;
use std::io::{BufReader, Stdin}; use std::io::{BufReader, Stdin};
@ -86,17 +86,18 @@ impl Config {
} }
pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult<Config> { pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult<Config> {
let app = base_app(about).override_usage(usage); let app = base_app(about, usage);
let arg_list = args let arg_list = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
Config::from(&app.get_matches_from(arg_list)) Config::from(&app.get_matches_from(arg_list))
} }
pub fn base_app(about: &str) -> App { pub fn base_app<'a>(about: &'a str, usage: &'a str) -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(about) .about(about)
.override_usage(format_usage(usage))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
// Format arguments. // Format arguments.
.arg( .arg(

View file

@ -23,16 +23,13 @@ to attempt to recover from any other non-alphabet bytes in the
encoded stream. encoded stream.
"; ";
fn usage() -> String { const USAGE: &str = "{0} [OPTION]... [FILE]";
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let format = Format::Base64; let format = Format::Base64;
let usage = usage();
let config: base_common::Config = base_common::parse_base_cmd_args(args, ABOUT, &usage)?; let config: base_common::Config = base_common::parse_base_cmd_args(args, ABOUT, USAGE)?;
// Create a reference to stdin so we can return a locked stdin from // Create a reference to stdin so we can return a locked stdin from
// parse_base_cmd_args // parse_base_cmd_args

View file

@ -11,18 +11,13 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::path::{is_separator, PathBuf}; use std::path::{is_separator, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError}; use uucore::error::{UResult, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static SUMMARY: &str = "Print NAME with any leading directory components removed static SUMMARY: &str = "Print NAME with any leading directory components removed
If specified, also remove a trailing SUFFIX"; If specified, also remove a trailing SUFFIX";
fn usage() -> String { const USAGE: &str = "{} NAME [SUFFIX]
format!( {} OPTION... NAME...";
"{0} NAME [SUFFIX]
{0} OPTION... NAME...",
uucore::execution_phrase()
)
}
pub mod options { pub mod options {
pub static MULTIPLE: &str = "multiple"; pub static MULTIPLE: &str = "multiple";
@ -36,11 +31,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = usage();
// //
// Argument parsing // Argument parsing
// //
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
// too few arguments // too few arguments
if !matches.is_present(options::NAME) { if !matches.is_present(options::NAME) {
@ -97,6 +91,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::MULTIPLE) Arg::new(options::MULTIPLE)

View file

@ -38,12 +38,10 @@ const ENCODINGS: &[(&str, Format)] = &[
("z85", Format::Z85), ("z85", Format::Z85),
]; ];
fn usage() -> String { const USAGE: &str = "{} [OPTION]... [FILE]";
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
}
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
let mut app = base_common::base_app(ABOUT); let mut app = base_common::base_app(ABOUT, USAGE);
for encoding in ENCODINGS { for encoding in ENCODINGS {
app = app.arg(Arg::new(encoding.0).long(encoding.0)); app = app.arg(Arg::new(encoding.0).long(encoding.0));
} }
@ -51,8 +49,7 @@ pub fn uu_app<'a>() -> App<'a> {
} }
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> { fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
let usage = usage(); let matches = uu_app().get_matches_from(
let matches = uu_app().override_usage(&usage[..]).get_matches_from(
args.collect_str(InvalidEncodingHandling::ConvertLossy) args.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(), .accept_any(),
); );

View file

@ -36,10 +36,10 @@ use std::net::Shutdown;
use std::os::unix::fs::FileTypeExt; use std::os::unix::fs::FileTypeExt;
#[cfg(unix)] #[cfg(unix)]
use unix_socket::UnixStream; use unix_socket::UnixStream;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static NAME: &str = "cat"; static NAME: &str = "cat";
static SYNTAX: &str = "[OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
static SUMMARY: &str = "Concatenate FILE(s), or standard input, to standard output static SUMMARY: &str = "Concatenate FILE(s), or standard input, to standard output
With no FILE, or when FILE is -, read standard input."; With no FILE, or when FILE is -, read standard input.";
@ -243,7 +243,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -3,6 +3,7 @@
#![allow(clippy::upper_case_acronyms)] #![allow(clippy::upper_case_acronyms)]
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::{display::Quotable, show_error, show_warning}; use uucore::{display::Quotable, show_error, show_warning};
use clap::{App, AppSettings, Arg}; use clap::{App, AppSettings, Arg};
@ -22,6 +23,10 @@ use errors::*;
static VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION: &str = env!("CARGO_PKG_VERSION");
static ABOUT: &str = "Change the SELinux security context of each FILE to CONTEXT. \n\ static ABOUT: &str = "Change the SELinux security context of each FILE to CONTEXT. \n\
With --reference, change the security context of each FILE to that of RFILE."; With --reference, change the security context of each FILE to that of RFILE.";
const USAGE: &str = "\
{} [OPTION]... CONTEXT FILE... \n \
{} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \
{} [OPTION]... --reference=RFILE FILE...";
pub mod options { pub mod options {
pub static VERBOSE: &str = "verbose"; pub static VERBOSE: &str = "verbose";
@ -52,20 +57,9 @@ pub mod options {
} }
} }
fn get_usage() -> String {
format!(
"{0} [OPTION]... CONTEXT FILE... \n \
{0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \
{0} [OPTION]... --reference=RFILE FILE...",
uucore::execution_phrase()
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let config = uu_app();
let config = uu_app().override_usage(usage.as_ref());
let options = match parse_command_line(config, args) { let options = match parse_command_line(config, args) {
Ok(r) => r, Ok(r) => r,
@ -164,6 +158,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::dereference::DEREFERENCE) Arg::new(options::dereference::DEREFERENCE)

View file

@ -10,6 +10,7 @@
use uucore::display::Quotable; use uucore::display::Quotable;
pub use uucore::entries; pub use uucore::entries;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use uucore::perms::{chown_base, options, IfFrom}; use uucore::perms::{chown_base, options, IfFrom};
use clap::{App, AppSettings, Arg, ArgMatches}; use clap::{App, AppSettings, Arg, ArgMatches};
@ -20,12 +21,9 @@ use std::os::unix::fs::MetadataExt;
static ABOUT: &str = "Change the group of each FILE to GROUP."; static ABOUT: &str = "Change the group of each FILE to GROUP.";
static VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION: &str = env!("CARGO_PKG_VERSION");
fn get_usage() -> String { const USAGE: &str = "\
format!( {} [OPTION]... GROUP FILE...\n \
"{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...", {} [OPTION]... --reference=RFILE FILE...";
uucore::execution_phrase()
)
}
fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> { fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> {
let dest_gid = if let Some(file) = matches.value_of(options::REFERENCE) { let dest_gid = if let Some(file) = matches.value_of(options::REFERENCE) {
@ -53,21 +51,14 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>,
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); chown_base(uu_app(), args, options::ARG_GROUP, parse_gid_and_uid, true)
chown_base(
uu_app().override_usage(&usage[..]),
args,
options::ARG_GROUP,
parse_gid_and_uid,
true,
)
} }
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::verbosity::CHANGES) Arg::new(options::verbosity::CHANGES)

View file

@ -17,7 +17,7 @@ use uucore::fs::display_permissions_unix;
use uucore::libc::mode_t; use uucore::libc::mode_t;
#[cfg(not(windows))] #[cfg(not(windows))]
use uucore::mode; use uucore::mode;
use uucore::{show_error, InvalidEncodingHandling}; use uucore::{format_usage, show_error, InvalidEncodingHandling};
use walkdir::WalkDir; use walkdir::WalkDir;
static ABOUT: &str = "Change the mode of each FILE to MODE. static ABOUT: &str = "Change the mode of each FILE to MODE.
@ -35,14 +35,10 @@ mod options {
pub const FILE: &str = "FILE"; pub const FILE: &str = "FILE";
} }
fn usage() -> String { const USAGE: &str = "\
format!( {} [OPTION]... MODE[,MODE]... FILE...
"{0} [OPTION]... MODE[,MODE]... FILE... {} [OPTION]... OCTAL-MODE FILE...
or: {0} [OPTION]... OCTAL-MODE FILE... {} [OPTION]... --reference=RFILE FILE...";
or: {0} [OPTION]... --reference=RFILE FILE...",
uucore::execution_phrase()
)
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.") String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.")
@ -58,13 +54,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
let mode_had_minus_prefix = mode::strip_minus_from_mode(&mut args); let mode_had_minus_prefix = mode::strip_minus_from_mode(&mut args);
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let changes = matches.is_present(options::CHANGES); let changes = matches.is_present(options::CHANGES);
let quiet = matches.is_present(options::QUIET); let quiet = matches.is_present(options::QUIET);
@ -125,6 +117,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::CHANGES) Arg::new(options::CHANGES)

View file

@ -9,6 +9,7 @@
use uucore::display::Quotable; use uucore::display::Quotable;
pub use uucore::entries::{self, Group, Locate, Passwd}; pub use uucore::entries::{self, Group, Locate, Passwd};
use uucore::format_usage;
use uucore::perms::{chown_base, options, IfFrom}; use uucore::perms::{chown_base, options, IfFrom};
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
@ -20,12 +21,9 @@ use std::os::unix::fs::MetadataExt;
static ABOUT: &str = "change file owner and group"; static ABOUT: &str = "change file owner and group";
fn get_usage() -> String { const USAGE: &str = "\
format!( {} [OPTION]... [OWNER][:[GROUP]] FILE...
"{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...", {} [OPTION]... --reference=RFILE FILE...";
uucore::execution_phrase()
)
}
fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> { fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> {
let filter = if let Some(spec) = matches.value_of(options::FROM) { let filter = if let Some(spec) = matches.value_of(options::FROM) {
@ -56,10 +54,8 @@ fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option<u32>, Optio
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage();
chown_base( chown_base(
uu_app().override_usage(&usage[..]), uu_app(),
args, args,
options::ARG_OWNER, options::ARG_OWNER,
parse_gid_uid_and_filter, parse_gid_uid_and_filter,
@ -71,6 +67,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::verbosity::CHANGES) Arg::new(options::verbosity::CHANGES)

View file

@ -17,10 +17,10 @@ use std::path::Path;
use std::process::Command; use std::process::Command;
use uucore::error::{set_exit_code, UResult}; use uucore::error::{set_exit_code, UResult};
use uucore::libc::{self, chroot, setgid, setgroups, setuid}; use uucore::libc::{self, chroot, setgid, setgroups, setuid};
use uucore::{entries, InvalidEncodingHandling}; use uucore::{entries, format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT."; static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT.";
static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; static USAGE: &str = "{} [OPTION]... NEWROOT [COMMAND [ARG]...]";
mod options { mod options {
pub const NEWROOT: &str = "newroot"; pub const NEWROOT: &str = "newroot";
@ -95,7 +95,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::NEWROOT) Arg::new(options::NEWROOT)

View file

@ -12,15 +12,15 @@ use std::io::{self, stdin, BufReader, Read};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::show;
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
use uucore::{format_usage, show};
// NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8 // NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8
const CRC_TABLE_LEN: usize = 256; const CRC_TABLE_LEN: usize = 256;
const CRC_TABLE: [u32; CRC_TABLE_LEN] = generate_crc_table(); const CRC_TABLE: [u32; CRC_TABLE_LEN] = generate_crc_table();
const NAME: &str = "cksum"; const NAME: &str = "cksum";
const SYNTAX: &str = "[OPTIONS] [FILE]..."; const USAGE: &str = "{} [OPTIONS] [FILE]...";
const SUMMARY: &str = "Print CRC and size for each file"; const SUMMARY: &str = "Print CRC and size for each file";
const fn generate_crc_table() -> [u32; CRC_TABLE_LEN] { const fn generate_crc_table() -> [u32; CRC_TABLE_LEN] {
@ -145,7 +145,7 @@ pub fn uu_app<'a>() -> App<'a> {
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)

View file

@ -13,12 +13,13 @@ use std::io::{self, stdin, BufRead, BufReader, Stdin};
use std::path::Path; use std::path::Path;
use uucore::error::FromIo; use uucore::error::FromIo;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
static ABOUT: &str = "compare two sorted files line by line"; static ABOUT: &str = "compare two sorted files line by line";
static LONG_HELP: &str = ""; static LONG_HELP: &str = "";
const USAGE: &str = "{} [OPTION]... FILE1 FILE2";
mod options { mod options {
pub const COLUMN_1: &str = "1"; pub const COLUMN_1: &str = "1";
@ -30,10 +31,6 @@ mod options {
pub const FILE_2: &str = "FILE2"; pub const FILE_2: &str = "FILE2";
} }
fn usage() -> String {
format!("{} [OPTION]... FILE1 FILE2", uucore::execution_phrase())
}
fn mkdelim(col: usize, opts: &ArgMatches) -> String { fn mkdelim(col: usize, opts: &ArgMatches) -> String {
let mut s = String::new(); let mut s = String::new();
let delim = opts.value_of(options::DELIMITER).unwrap(); let delim = opts.value_of(options::DELIMITER).unwrap();
@ -132,12 +129,11 @@ fn open_file(name: &str) -> io::Result<LineReader> {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
let filename1 = matches.value_of(options::FILE_1).unwrap(); let filename1 = matches.value_of(options::FILE_1).unwrap();
let filename2 = matches.value_of(options::FILE_2).unwrap(); let filename2 = matches.value_of(options::FILE_2).unwrap();
let mut f1 = open_file(filename1).map_err_context(|| filename1.to_string())?; let mut f1 = open_file(filename1).map_err_context(|| filename1.to_string())?;
@ -152,6 +148,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::COLUMN_1) Arg::new(options::COLUMN_1)

View file

@ -19,6 +19,7 @@ extern crate quick_error;
extern crate uucore; extern crate uucore;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::format_usage;
use uucore::fs::FileInformation; use uucore::fs::FileInformation;
#[cfg(windows)] #[cfg(windows)]
use winapi::um::fileapi::CreateFileW; use winapi::um::fileapi::CreateFileW;
@ -230,14 +231,10 @@ static ABOUT: &str = "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.";
static LONG_HELP: &str = ""; static LONG_HELP: &str = "";
static EXIT_ERR: i32 = 1; static EXIT_ERR: i32 = 1;
fn usage() -> String { const USAGE: &str = "\
format!( {} [OPTION]... [-T] SOURCE DEST
"{0} [OPTION]... [-T] SOURCE DEST {} [OPTION]... SOURCE... DIRECTORY
{0} [OPTION]... SOURCE... DIRECTORY {} [OPTION]... -t DIRECTORY SOURCE...";
{0} [OPTION]... -t DIRECTORY SOURCE...",
uucore::execution_phrase()
)
}
// Argument constants // Argument constants
mod options { mod options {
@ -300,6 +297,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(options::TARGET_DIRECTORY) .arg(Arg::new(options::TARGET_DIRECTORY)
.short('t') .short('t')
@ -456,14 +454,12 @@ pub fn uu_app<'a>() -> App<'a> {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let matches = uu_app() let matches = uu_app()
.after_help(&*format!( .after_help(&*format!(
"{}\n{}", "{}\n{}",
LONG_HELP, LONG_HELP,
backup_control::BACKUP_CONTROL_LONG_HELP backup_control::BACKUP_CONTROL_LONG_HELP
)) ))
.override_usage(&usage[..])
.get_matches_from(args); .get_matches_from(args);
let options = Options::from_matches(&matches)?; let options = Options::from_matches(&matches)?;

View file

@ -16,7 +16,7 @@ use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use regex::Regex; use regex::Regex;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
mod csplit_error; mod csplit_error;
mod patterns; mod patterns;
@ -27,6 +27,7 @@ use crate::split_name::SplitName;
static SUMMARY: &str = "split a file into sections determined by context lines"; static SUMMARY: &str = "split a file into sections determined by context lines";
static LONG_HELP: &str = "Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output."; static LONG_HELP: &str = "Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.";
const USAGE: &str = "{} [OPTION]... FILE PATTERN...";
mod options { mod options {
pub const SUFFIX_FORMAT: &str = "suffix-format"; pub const SUFFIX_FORMAT: &str = "suffix-format";
@ -40,13 +41,6 @@ mod options {
pub const PATTERN: &str = "pattern"; pub const PATTERN: &str = "pattern";
} }
fn usage() -> String {
format!(
"{0} [OPTION]... FILE PATTERN...",
uucore::execution_phrase()
)
}
/// Command line options for csplit. /// Command line options for csplit.
pub struct CsplitOptions { pub struct CsplitOptions {
split_name: crate::SplitName, split_name: crate::SplitName,
@ -719,12 +713,11 @@ mod tests {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
// get the file to split // get the file to split
let file_name = matches.value_of(options::FILE).unwrap(); let file_name = matches.value_of(options::FILE).unwrap();
@ -757,6 +750,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::SUFFIX_FORMAT) Arg::new(options::SUFFIX_FORMAT)

View file

@ -20,13 +20,13 @@ use uucore::error::{FromIo, UResult, USimpleError};
use self::searcher::Searcher; use self::searcher::Searcher;
use uucore::ranges::Range; use uucore::ranges::Range;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
mod searcher; mod searcher;
static NAME: &str = "cut"; static NAME: &str = "cut";
static SYNTAX: &str = static USAGE: &str =
"[-d] [-s] [-z] [--output-delimiter] ((-f|-b|-c) {{sequence}}) {{sourcefile}}+"; "{} [-d] [-s] [-z] [--output-delimiter] ((-f|-b|-c) {{sequence}}) {{sourcefile}}+";
static SUMMARY: &str = static SUMMARY: &str =
"Prints specified byte or field columns from each line of stdin or the input files"; "Prints specified byte or field columns from each line of stdin or the input files";
static LONG_HELP: &str = " static LONG_HELP: &str = "
@ -537,7 +537,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)

View file

@ -21,7 +21,7 @@ use uucore::display::Quotable;
#[cfg(not(any(target_os = "macos", target_os = "redox")))] #[cfg(not(any(target_os = "macos", target_os = "redox")))]
use uucore::error::FromIo; use uucore::error::FromIo;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::show_error; use uucore::{format_usage, show_error};
#[cfg(windows)] #[cfg(windows)]
use winapi::{ use winapi::{
shared::minwindef::WORD, shared::minwindef::WORD,
@ -38,8 +38,10 @@ const MINUTE: &str = "minute";
const SECOND: &str = "second"; const SECOND: &str = "second";
const NS: &str = "ns"; const NS: &str = "ns";
const NAME: &str = "date";
const ABOUT: &str = "print or set the system date and time"; const ABOUT: &str = "print or set the system date and time";
const USAGE: &str = "\
{} [OPTION]... [+FORMAT]...
{} [OPTION]... [MMDDhhmm[[CC]YY][.ss]]";
const OPT_DATE: &str = "date"; const OPT_DATE: &str = "date";
const OPT_FORMAT: &str = "format"; const OPT_FORMAT: &str = "format";
@ -142,12 +144,7 @@ impl<'a> From<&'a str> for Rfc3339Format {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let syntax = format!( let matches = uu_app().get_matches_from(args);
"{0} [OPTION]... [+FORMAT]...
{0} [OPTION]... [MMDDhhmm[[CC]YY][.ss]]",
NAME
);
let matches = uu_app().override_usage(&syntax[..]).get_matches_from(args);
let format = if let Some(form) = matches.value_of(OPT_FORMAT) { let format = if let Some(form) = matches.value_of(OPT_FORMAT) {
if !form.starts_with('+') { if !form.starts_with('+') {
@ -261,6 +258,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_DATE) Arg::new(OPT_DATE)

View file

@ -7,10 +7,10 @@
// that was distributed with this source code. // that was distributed with this source code.
mod table; mod table;
use uucore::error::UResult;
#[cfg(unix)] #[cfg(unix)]
use uucore::fsext::statfs_fn; use uucore::fsext::statfs_fn;
use uucore::fsext::{read_fs_list, FsUsage, MountInfo}; use uucore::fsext::{read_fs_list, FsUsage, MountInfo};
use uucore::{error::UResult, format_usage};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
@ -28,6 +28,7 @@ use crate::table::{DisplayRow, Header, Row};
static ABOUT: &str = "Show information about the file system on which each FILE resides,\n\ static ABOUT: &str = "Show information about the file system on which each FILE resides,\n\
or all file systems by default."; or all file systems by default.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
static OPT_ALL: &str = "all"; static OPT_ALL: &str = "all";
static OPT_BLOCKSIZE: &str = "blocksize"; static OPT_BLOCKSIZE: &str = "blocksize";
@ -94,10 +95,6 @@ struct Filesystem {
usage: FsUsage, usage: FsUsage,
} }
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
impl FsSelector { impl FsSelector {
/// Convert command-line arguments into a [`FsSelector`]. /// Convert command-line arguments into a [`FsSelector`].
/// ///
@ -256,8 +253,7 @@ fn filter_mount_list(vmi: Vec<MountInfo>, paths: &[String], opt: &Options) -> Ve
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of(OPT_PATHS) .values_of(OPT_PATHS)
@ -293,6 +289,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_ALL) Arg::new(OPT_ALL)

View file

@ -24,7 +24,7 @@ mod options {
pub const FILE: &str = "FILE"; pub const FILE: &str = "FILE";
} }
static SYNTAX: &str = "[OPTION]... [FILE]"; static USAGE: &str = "{} [OPTION]... [FILE]";
static SUMMARY: &str = "Output commands to set the LS_COLORS environment variable."; static SUMMARY: &str = "Output commands to set the LS_COLORS environment variable.";
static LONG_HELP: &str = " static LONG_HELP: &str = "
If FILE is specified, read it to determine which colors to use for which If FILE is specified, read it to determine which colors to use for which
@ -61,19 +61,13 @@ pub fn guess_syntax() -> OutputFmt {
} }
} }
fn usage() -> String {
format!("{0} {1}", uucore::execution_phrase(), SYNTAX)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage(); let matches = uu_app().get_matches_from(&args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(&args);
let files = matches let files = matches
.values_of(options::FILE) .values_of(options::FILE)
@ -165,6 +159,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::BOURNE_SHELL) Arg::new(options::BOURNE_SHELL)
@ -257,7 +252,7 @@ enum ParseState {
Pass, Pass,
} }
use std::collections::HashMap; use std::collections::HashMap;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String> fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String>
where where

View file

@ -9,19 +9,16 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::path::Path; use std::path::Path;
use uucore::display::print_verbatim; use uucore::display::print_verbatim;
use uucore::error::{UResult, UUsageError}; use uucore::error::{UResult, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "strip last component from file name"; static ABOUT: &str = "strip last component from file name";
const USAGE: &str = "{} [OPTION] NAME...";
mod options { mod options {
pub const ZERO: &str = "zero"; pub const ZERO: &str = "zero";
pub const DIR: &str = "dir"; pub const DIR: &str = "dir";
} }
fn usage() -> String {
format!("{0} [OPTION] NAME...", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( String::from(
"Output each NAME with its last non-slash component and trailing slashes "Output each NAME with its last non-slash component and trailing slashes
@ -35,13 +32,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let separator = if matches.is_present(options::ZERO) { let separator = if matches.is_present(options::ZERO) {
"\0" "\0"
@ -87,6 +80,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.about(ABOUT) .about(ABOUT)
.version(crate_version!()) .version(crate_version!())
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ZERO) Arg::new(options::ZERO)

View file

@ -33,6 +33,7 @@ use std::time::{Duration, UNIX_EPOCH};
use std::{error::Error, fmt::Display}; use std::{error::Error, fmt::Display};
use uucore::display::{print_verbatim, Quotable}; use uucore::display::{print_verbatim, Quotable};
use uucore::error::{UError, UResult}; use uucore::error::{UError, UResult};
use uucore::format_usage;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
#[cfg(windows)] #[cfg(windows)]
@ -80,6 +81,9 @@ SIZE is an integer and optional unit (example: 10M is 10*1024*1024).
Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB,... (powers Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB,... (powers
of 1000). of 1000).
"; ";
const USAGE: &str = "\
{} [OPTION]... [FILE]...
{} [OPTION]... --files0-from=F";
// TODO: Support Z & Y (currently limited by size of u64) // TODO: Support Z & Y (currently limited by size of u64)
const UNITS: [(char, u32); 6] = [('E', 6), ('P', 5), ('T', 4), ('G', 3), ('M', 2), ('K', 1)]; const UNITS: [(char, u32); 6] = [('E', 6), ('P', 5), ('T', 4), ('G', 3), ('M', 2), ('K', 1)];
@ -391,14 +395,6 @@ fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String {
format!("{}", ((size as f64) / (block_size as f64)).ceil()) format!("{}", ((size as f64) / (block_size as f64)).ceil())
} }
fn usage() -> String {
format!(
"{0} [OPTION]... [FILE]...
{0} [OPTION]... --files0-from=F",
uucore::execution_phrase()
)
}
#[derive(Debug)] #[derive(Debug)]
enum DuError { enum DuError {
InvalidMaxDepthArg(String), InvalidMaxDepthArg(String),
@ -459,9 +455,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let summarize = matches.is_present(options::SUMMARIZE); let summarize = matches.is_present(options::SUMMARIZE);
@ -629,6 +623,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ALL) Arg::new(options::ALL)

View file

@ -11,11 +11,11 @@ use std::io::{self, Write};
use std::iter::Peekable; use std::iter::Peekable;
use std::str::Chars; use std::str::Chars;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
const NAME: &str = "echo"; const NAME: &str = "echo";
const SUMMARY: &str = "display a line of text"; const SUMMARY: &str = "display a line of text";
const USAGE: &str = "[OPTIONS]... [STRING]..."; const USAGE: &str = "{} [OPTIONS]... [STRING]...";
const AFTER_HELP: &str = r#" const AFTER_HELP: &str = r#"
Echo the STRING(s) to standard output. Echo the STRING(s) to standard output.
@ -138,7 +138,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.arg( .arg(
Arg::new(options::NO_NEWLINE) Arg::new(options::NO_NEWLINE)
.short('n') .short('n')

View file

@ -25,8 +25,9 @@ use std::iter::Iterator;
use std::process::Command; use std::process::Command;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::format_usage;
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]"; const USAGE: &str = "{} [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
const AFTER_HELP: &str = "\ const AFTER_HELP: &str = "\
A mere - implies -i. If no COMMAND, print the resulting environment. A mere - implies -i. If no COMMAND, print the resulting environment.
"; ";
@ -125,7 +126,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.author(crate_authors!()) .author(crate_authors!())
.about(crate_description!()) .about(crate_description!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
.setting(AppSettings::AllowExternalSubcommands) .setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)

View file

@ -19,9 +19,11 @@ use std::str::from_utf8;
use unicode_width::UnicodeWidthChar; use unicode_width::UnicodeWidthChar;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::format_usage;
static ABOUT: &str = "Convert tabs in each FILE to spaces, writing to standard output. static ABOUT: &str = "Convert tabs in each FILE to spaces, writing to standard output.
With no FILE, or when FILE is -, read standard input."; With no FILE, or when FILE is -, read standard input.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
pub mod options { pub mod options {
pub static TABS: &str = "tabs"; pub static TABS: &str = "tabs";
@ -34,10 +36,6 @@ static LONG_HELP: &str = "";
static DEFAULT_TABSTOP: usize = 8; static DEFAULT_TABSTOP: usize = 8;
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
/// The mode to use when replacing tabs beyond the last one specified in /// The mode to use when replacing tabs beyond the last one specified in
/// the `--tabs` argument. /// the `--tabs` argument.
enum RemainingMode { enum RemainingMode {
@ -173,8 +171,7 @@ impl Options {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
expand(&Options::new(&matches)).map_err_context(|| "failed to write output".to_string()) expand(&Options::new(&matches)).map_err_context(|| "failed to write output".to_string())
} }
@ -184,6 +181,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::INITIAL) Arg::new(options::INITIAL)

View file

@ -17,6 +17,7 @@ use std::io::{stdin, stdout, Write};
use std::io::{BufReader, BufWriter, Read}; use std::io::{BufReader, BufWriter, Read};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use self::linebreak::break_lines; use self::linebreak::break_lines;
use self::parasplit::ParagraphStream; use self::parasplit::ParagraphStream;
@ -25,6 +26,7 @@ mod linebreak;
mod parasplit; mod parasplit;
static ABOUT: &str = "Reformat paragraphs from input files (or stdin) to stdout."; static ABOUT: &str = "Reformat paragraphs from input files (or stdin) to stdout.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
static MAX_WIDTH: usize = 2500; static MAX_WIDTH: usize = 2500;
static OPT_CROWN_MARGIN: &str = "crown-margin"; static OPT_CROWN_MARGIN: &str = "crown-margin";
@ -43,10 +45,6 @@ static OPT_TAB_WIDTH: &str = "tab-width";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!("{} [OPTION]... [FILE]...", uucore::execution_phrase())
}
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>; pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;
pub struct FmtOptions { pub struct FmtOptions {
crown: bool, crown: bool,
@ -69,9 +67,7 @@ pub struct FmtOptions {
#[uucore::main] #[uucore::main]
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let mut files: Vec<String> = matches let mut files: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -226,6 +222,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_CROWN_MARGIN) Arg::new(OPT_CROWN_MARGIN)

View file

@ -13,12 +13,12 @@ use std::io::{stdin, BufRead, BufReader, Read};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
const TAB_WIDTH: usize = 8; const TAB_WIDTH: usize = 8;
static NAME: &str = "fold"; static NAME: &str = "fold";
static SYNTAX: &str = "[OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
static SUMMARY: &str = "Writes each file (or standard input if no files are given) static SUMMARY: &str = "Writes each file (or standard input if no files are given)
to standard output whilst breaking long lines"; to standard output whilst breaking long lines";
@ -67,7 +67,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -23,6 +23,7 @@ use uucore::{
display::Quotable, display::Quotable,
entries::{get_groups_gnu, gid2grp, Locate, Passwd}, entries::{get_groups_gnu, gid2grp, Locate, Passwd},
error::{UError, UResult}, error::{UError, UResult},
format_usage,
}; };
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
@ -34,9 +35,7 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \
if no USERNAME is specified, for\nthe current process \ if no USERNAME is specified, for\nthe current process \
(which may differ if the groups database has changed)."; (which may differ if the groups database has changed).";
fn usage() -> String { const USAGE: &str = "{} [OPTION]... [USERNAME]...";
format!("{0} [OPTION]... [USERNAME]...", uucore::execution_phrase())
}
#[derive(Debug)] #[derive(Debug)]
enum GroupsError { enum GroupsError {
@ -71,9 +70,7 @@ fn infallible_gid2grp(gid: &u32) -> String {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::USERS) .values_of(options::USERS)
@ -109,6 +106,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::USERS) Arg::new(options::USERS)

View file

@ -12,7 +12,7 @@ use std::io::{self, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError}; use uucore::error::{FromIo, UError, UResult, USimpleError};
use uucore::lines::lines; use uucore::lines::lines;
use uucore::show; use uucore::{format_usage, show};
const BUF_SIZE: usize = 65536; const BUF_SIZE: usize = 65536;
@ -26,7 +26,7 @@ const ABOUT: &str = "\
\n\ \n\
Mandatory arguments to long flags are mandatory for short flags too.\ Mandatory arguments to long flags are mandatory for short flags too.\
"; ";
const USAGE: &str = "head [FLAG]... [FILE]..."; const USAGE: &str = "{} [FLAG]... [FILE]...";
mod options { mod options {
pub const BYTES_NAME: &str = "BYTES"; pub const BYTES_NAME: &str = "BYTES";
@ -45,7 +45,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::BYTES_NAME) Arg::new(options::BYTES_NAME)

View file

@ -9,9 +9,9 @@
use clap::{crate_version, App, AppSettings}; use clap::{crate_version, App, AppSettings};
use libc::c_long; use libc::c_long;
use uucore::error::UResult; use uucore::{error::UResult, format_usage};
static SYNTAX: &str = "[options]"; const USAGE: &str = "{} [options]";
const SUMMARY: &str = "Print the numeric identifier (in hexadecimal) for the current host"; const SUMMARY: &str = "Print the numeric identifier (in hexadecimal) for the current host";
// currently rust libc interface doesn't include gethostid // currently rust libc interface doesn't include gethostid
@ -30,7 +30,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.override_usage(SYNTAX) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
} }

View file

@ -13,9 +13,13 @@ use std::str;
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use uucore::error::{FromIo, UResult}; use uucore::{
error::{FromIo, UResult},
format_usage,
};
static ABOUT: &str = "Display or set the system's host name."; static ABOUT: &str = "Display or set the system's host name.";
const USAGE: &str = "{} [OPTION]... [HOSTNAME]";
static OPT_DOMAIN: &str = "domain"; static OPT_DOMAIN: &str = "domain";
static OPT_IP_ADDRESS: &str = "ip-address"; static OPT_IP_ADDRESS: &str = "ip-address";
@ -54,14 +58,9 @@ mod wsa {
} }
} }
fn usage() -> String {
format!("{0} [OPTION]... [HOSTNAME]", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
#[cfg(windows)] #[cfg(windows)]
let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?; let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?;
@ -76,6 +75,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_DOMAIN) Arg::new(OPT_DOMAIN)

View file

@ -45,6 +45,7 @@ use uucore::display::Quotable;
use uucore::entries::{self, Group, Locate, Passwd}; use uucore::entries::{self, Group, Locate, Passwd};
use uucore::error::UResult; use uucore::error::UResult;
use uucore::error::{set_exit_code, USimpleError}; use uucore::error::{set_exit_code, USimpleError};
use uucore::format_usage;
pub use uucore::libc; pub use uucore::libc;
use uucore::libc::{getlogin, uid_t}; use uucore::libc::{getlogin, uid_t};
use uucore::process::{getegid, geteuid, getgid, getuid}; use uucore::process::{getegid, geteuid, getgid, getuid};
@ -57,6 +58,7 @@ macro_rules! cstr2cow {
static ABOUT: &str = "Print user and group information for each specified USER, static ABOUT: &str = "Print user and group information for each specified USER,
or (when USER omitted) for the current user."; or (when USER omitted) for the current user.";
const USAGE: &str = "{} [OPTION]... [USER]...";
#[cfg(not(feature = "selinux"))] #[cfg(not(feature = "selinux"))]
static CONTEXT_HELP_TEXT: &str = "print only the security context of the process (not enabled)"; static CONTEXT_HELP_TEXT: &str = "print only the security context of the process (not enabled)";
@ -77,10 +79,6 @@ mod options {
pub const ARG_USERS: &str = "USER"; pub const ARG_USERS: &str = "USER";
} }
fn usage() -> String {
format!("{0} [OPTION]... [USER]...", uucore::execution_phrase())
}
fn get_description() -> String { fn get_description() -> String {
String::from( String::from(
"The id utility displays the user and group names and numeric IDs, of the \ "The id utility displays the user and group names and numeric IDs, of the \
@ -128,13 +126,9 @@ struct State {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let after_help = get_description(); let after_help = get_description();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::ARG_USERS) .values_of(options::ARG_USERS)
@ -351,6 +345,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::OPT_AUDIT) Arg::new(options::OPT_AUDIT)

View file

@ -19,6 +19,7 @@ use uucore::backup_control::{self, BackupMode};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::entries::{grp2gid, usr2uid}; use uucore::entries::{grp2gid, usr2uid};
use uucore::error::{FromIo, UError, UIoError, UResult}; use uucore::error::{FromIo, UError, UIoError, UResult};
use uucore::format_usage;
use uucore::mode::get_umask; use uucore::mode::get_umask;
use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel}; use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel};
@ -144,6 +145,7 @@ impl Behavior {
static ABOUT: &str = "Copy SOURCE to DEST or multiple SOURCE(s) to the existing static ABOUT: &str = "Copy SOURCE to DEST or multiple SOURCE(s) to the existing
DIRECTORY, while setting permission modes and owner/group"; DIRECTORY, while setting permission modes and owner/group";
const USAGE: &str = "{} [OPTION]... [FILE]...";
static OPT_COMPARE: &str = "compare"; static OPT_COMPARE: &str = "compare";
static OPT_DIRECTORY: &str = "directory"; static OPT_DIRECTORY: &str = "directory";
@ -163,19 +165,13 @@ static OPT_CONTEXT: &str = "context";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
/// Main install utility function, called from main.rs. /// Main install utility function, called from main.rs.
/// ///
/// Returns a program return code. /// Returns a program return code.
/// ///
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -196,6 +192,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
backup_control::arguments::backup() backup_control::arguments::backup()

View file

@ -16,9 +16,10 @@ use std::io::Error;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::signals::{signal_by_name_or_value, ALL_SIGNALS}; use uucore::signals::{signal_by_name_or_value, ALL_SIGNALS};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Send signal to processes or list information about signals."; static ABOUT: &str = "Send signal to processes or list information about signals.";
const USAGE: &str = "{} [OPTIONS]... PID...";
pub mod options { pub mod options {
pub static PIDS_OR_SIGNALS: &str = "pids_of_signals"; pub static PIDS_OR_SIGNALS: &str = "pids_of_signals";
@ -42,8 +43,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.accept_any(); .accept_any();
let obs_signal = handle_obsolete(&mut args); let obs_signal = handle_obsolete(&mut args);
let usage = format!("{} [OPTIONS]... PID...", uucore::execution_phrase()); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) { let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) {
Mode::Table Mode::Table
@ -82,6 +82,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::LIST) Arg::new(options::LIST)

View file

@ -9,21 +9,18 @@ use std::fs::hard_link;
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::format_usage;
static ABOUT: &str = "Call the link function to create a link named FILE2 to an existing FILE1."; static ABOUT: &str = "Call the link function to create a link named FILE2 to an existing FILE1.";
const USAGE: &str = "{} FILE1 FILE2";
pub mod options { pub mod options {
pub static FILES: &str = "FILES"; pub static FILES: &str = "FILES";
} }
fn usage() -> String {
format!("{0} FILE1 FILE2", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let files: Vec<_> = matches let files: Vec<_> = matches
.values_of_os(options::FILES) .values_of_os(options::FILES)
@ -40,6 +37,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FILES) Arg::new(options::FILES)

View file

@ -13,6 +13,7 @@ extern crate uucore;
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UError, UResult}; use uucore::error::{UError, UResult};
use uucore::format_usage;
use std::borrow::Cow; use std::borrow::Cow;
use std::error::Error; use std::error::Error;
@ -90,16 +91,6 @@ impl UError for LnError {
} }
} }
fn usage() -> String {
format!(
"{0} [OPTION]... [-T] TARGET LINK_NAME (1st form)
{0} [OPTION]... TARGET (2nd form)
{0} [OPTION]... TARGET... DIRECTORY (3rd form)
{0} [OPTION]... -t DIRECTORY TARGET... (4th form)",
uucore::execution_phrase()
)
}
fn long_usage() -> String { fn long_usage() -> String {
String::from( String::from(
" In the 1st form, create a link to TARGET with the name LINK_NAME. " In the 1st form, create a link to TARGET with the name LINK_NAME.
@ -115,6 +106,11 @@ fn long_usage() -> String {
} }
static ABOUT: &str = "change file owner and group"; static ABOUT: &str = "change file owner and group";
const USAGE: &str = "\
{} [OPTION]... [-T] TARGET LINK_NAME
{} [OPTION]... TARGET
{} [OPTION]... TARGET... DIRECTORY
{} [OPTION]... -t DIRECTORY TARGET...";
mod options { mod options {
pub const FORCE: &str = "force"; pub const FORCE: &str = "force";
@ -131,11 +127,9 @@ static ARG_FILES: &str = "files";
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let long_usage = long_usage(); let long_usage = long_usage();
let matches = uu_app() let matches = uu_app()
.override_usage(&usage[..])
.after_help(&*format!( .after_help(&*format!(
"{}\n{}", "{}\n{}",
long_usage, long_usage,
@ -183,6 +177,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(backup_control::arguments::backup()) .arg(backup_control::arguments::backup())
.arg(backup_control::arguments::backup_no_args()) .arg(backup_control::arguments::backup_no_args())

View file

@ -35,17 +35,13 @@ fn get_userlogin() -> Option<String> {
static SUMMARY: &str = "Print user's login name"; static SUMMARY: &str = "Print user's login name";
fn usage() -> &'static str {
uucore::execution_phrase()
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let _ = uu_app().override_usage(usage()).get_matches_from(args); let _ = uu_app().get_matches_from(args);
match get_userlogin() { match get_userlogin() {
Some(userlogin) => println!("{}", userlogin), Some(userlogin) => println!("{}", userlogin),
@ -58,6 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.override_usage(uucore::execution_phrase())
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
} }

View file

@ -48,16 +48,14 @@ use uucore::{
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
#[cfg(unix)] #[cfg(unix)]
use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR};
use uucore::{fs::display_permissions, version_cmp::version_cmp}; use uucore::{format_usage, fs::display_permissions, version_cmp::version_cmp};
#[cfg(not(feature = "selinux"))] #[cfg(not(feature = "selinux"))]
static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)"; static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)";
#[cfg(feature = "selinux")] #[cfg(feature = "selinux")]
static CONTEXT_HELP_TEXT: &str = "print any security context of each file"; static CONTEXT_HELP_TEXT: &str = "print any security context of each file";
fn usage() -> String { const USAGE: &str = "{} [OPTION]... [FILE]...";
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
pub mod options { pub mod options {
@ -707,9 +705,7 @@ impl Config {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let app = uu_app();
let app = uu_app().override_usage(&usage[..]);
let matches = app.get_matches_from(args); let matches = app.get_matches_from(args);
@ -726,6 +722,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.override_usage(format_usage(USAGE))
.about( .about(
"By default, ls will list the files and contents of any directories on \ "By default, ls will list the files and contents of any directories on \
the command line, expect that it will ignore files and directories \ the command line, expect that it will ignore files and directories \

View file

@ -17,11 +17,13 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
#[cfg(not(windows))] #[cfg(not(windows))]
use uucore::mode; use uucore::mode;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static DEFAULT_PERM: u32 = 0o755; static DEFAULT_PERM: u32 = 0o755;
static ABOUT: &str = "Create the given DIRECTORY(ies) if they do not exist"; static ABOUT: &str = "Create the given DIRECTORY(ies) if they do not exist";
const USAGE: &str = "{} [OPTION]... [USER]";
mod options { mod options {
pub const MODE: &str = "mode"; pub const MODE: &str = "mode";
pub const PARENTS: &str = "parents"; pub const PARENTS: &str = "parents";
@ -29,9 +31,6 @@ mod options {
pub const DIRS: &str = "dirs"; pub const DIRS: &str = "dirs";
} }
fn usage() -> String {
format!("{0} [OPTION]... [USER]", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.") String::from("Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.")
} }
@ -87,17 +86,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Before we can parse 'args' with clap (and previously getopts), // Before we can parse 'args' with clap (and previously getopts),
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
let mode_had_minus_prefix = strip_minus_from_mode(&mut args); let mode_had_minus_prefix = strip_minus_from_mode(&mut args);
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
// Linux-specific options, not implemented // Linux-specific options, not implemented
// opts.optflag("Z", "context", "set SELinux security context" + // opts.optflag("Z", "context", "set SELinux security context" +
// " of each created directory to CTX"), // " of each created directory to CTX"),
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let dirs = matches.values_of_os(options::DIRS).unwrap_or_default(); let dirs = matches.values_of_os(options::DIRS).unwrap_or_default();
let verbose = matches.is_present(options::VERBOSE); let verbose = matches.is_present(options::VERBOSE);
@ -113,6 +107,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::MODE) Arg::new(options::MODE)

View file

@ -12,10 +12,11 @@ use clap::{crate_version, App, AppSettings, Arg};
use libc::mkfifo; use libc::mkfifo;
use std::ffi::CString; use std::ffi::CString;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
use uucore::{display::Quotable, InvalidEncodingHandling}; use uucore::{display::Quotable, InvalidEncodingHandling};
static NAME: &str = "mkfifo"; static NAME: &str = "mkfifo";
static USAGE: &str = "mkfifo [OPTION]... NAME..."; static USAGE: &str = "{} [OPTION]... NAME...";
static SUMMARY: &str = "Create a FIFO with the given name."; static SUMMARY: &str = "Create a FIFO with the given name.";
mod options { mod options {
@ -73,7 +74,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -15,10 +15,10 @@ use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOT
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError}; use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Create the special file NAME of the given TYPE."; static ABOUT: &str = "Create the special file NAME of the given TYPE.";
static USAGE: &str = "mknod [OPTION]... NAME TYPE [MAJOR MINOR]"; static USAGE: &str = "{} [OPTION]... NAME TYPE [MAJOR MINOR]";
static LONG_HELP: &str = "Mandatory arguments to long options are mandatory for short options too. static LONG_HELP: &str = "Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file permission bits to MODE, not a=rw - umask -m, --mode=MODE set file permission bits to MODE, not a=rw - umask
--help display this help and exit --help display this help and exit
@ -146,7 +146,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.after_help(LONG_HELP) .after_help(LONG_HELP)
.about(ABOUT) .about(ABOUT)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)

View file

@ -11,6 +11,7 @@
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::display::{println_verbatim, Quotable}; use uucore::display::{println_verbatim, Quotable};
use uucore::error::{FromIo, UError, UResult}; use uucore::error::{FromIo, UError, UResult};
use uucore::format_usage;
use std::env; use std::env;
use std::error::Error; use std::error::Error;
@ -22,6 +23,7 @@ use rand::Rng;
use tempfile::Builder; use tempfile::Builder;
static ABOUT: &str = "create a temporary file or directory."; static ABOUT: &str = "create a temporary file or directory.";
const USAGE: &str = "{} [OPTION]... [TEMPLATE]";
static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX"; static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX";
@ -34,10 +36,6 @@ static OPT_T: &str = "t";
static ARG_TEMPLATE: &str = "template"; static ARG_TEMPLATE: &str = "template";
fn usage() -> String {
format!("{0} [OPTION]... [TEMPLATE]", uucore::execution_phrase())
}
#[derive(Debug)] #[derive(Debug)]
enum MkTempError { enum MkTempError {
PersistError(PathBuf), PersistError(PathBuf),
@ -76,9 +74,7 @@ impl Display for MkTempError {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let template = matches.value_of(ARG_TEMPLATE).unwrap(); let template = matches.value_of(ARG_TEMPLATE).unwrap();
let tmpdir = matches.value_of(OPT_TMPDIR).unwrap_or_default(); let tmpdir = matches.value_of(OPT_TMPDIR).unwrap_or_default();
@ -139,6 +135,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_DIRECTORY) Arg::new(OPT_DIRECTORY)

View file

@ -26,6 +26,7 @@ use std::path::{Path, PathBuf};
use uucore::backup_control::{self, BackupMode}; use uucore::backup_control::{self, BackupMode};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use fs_extra::dir::{move_dir, CopyOptions as DirCopyOptions}; use fs_extra::dir::{move_dir, CopyOptions as DirCopyOptions};
@ -51,6 +52,10 @@ pub enum OverwriteMode {
static ABOUT: &str = "Move SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY."; static ABOUT: &str = "Move SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.";
static LONG_HELP: &str = ""; static LONG_HELP: &str = "";
const USAGE: &str = "\
{} [OPTION]... [-T] SOURCE DEST
{} [OPTION]... SOURCE... DIRECTORY
{} [OPTION]... -t DIRECTORY SOURCE...";
static OPT_FORCE: &str = "force"; static OPT_FORCE: &str = "force";
static OPT_INTERACTIVE: &str = "interactive"; static OPT_INTERACTIVE: &str = "interactive";
@ -63,26 +68,14 @@ static OPT_VERBOSE: &str = "verbose";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!(
"{0} [OPTION]... [-T] SOURCE DEST
{0} [OPTION]... SOURCE... DIRECTORY
{0} [OPTION]... -t DIRECTORY SOURCE...",
uucore::execution_phrase()
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let matches = uu_app() let matches = uu_app()
.after_help(&*format!( .after_help(&*format!(
"{}\n{}", "{}\n{}",
LONG_HELP, LONG_HELP,
backup_control::BACKUP_CONTROL_LONG_HELP backup_control::BACKUP_CONTROL_LONG_HELP
)) ))
.override_usage(&usage[..])
.get_matches_from(args); .get_matches_from(args);
let files: Vec<OsString> = matches let files: Vec<OsString> = matches
@ -123,6 +116,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
backup_control::arguments::backup() backup_control::arguments::backup()

View file

@ -16,31 +16,26 @@ use std::io::Error;
use std::ptr; use std::ptr;
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError}; use uucore::{
error::{set_exit_code, UResult, USimpleError, UUsageError},
format_usage,
};
pub mod options { pub mod options {
pub static ADJUSTMENT: &str = "adjustment"; pub static ADJUSTMENT: &str = "adjustment";
pub static COMMAND: &str = "COMMAND"; pub static COMMAND: &str = "COMMAND";
} }
fn usage() -> String { const ABOUT: &str = "\
format!( Run COMMAND with an adjusted niceness, which affects process scheduling. \
" With no COMMAND, print the current niceness. Niceness values range from at \
{0} [OPTIONS] [COMMAND [ARGS]] least -20 (most favorable to the process) to 19 (least favorable to the \
process).";
Run COMMAND with an adjusted niceness, which affects process scheduling. const USAGE: &str = "{} [OPTIONS] [COMMAND [ARGS]]";
With no COMMAND, print the current niceness. Niceness values range from at
least -20 (most favorable to the process) to 19 (least favorable to the
process).",
uucore::execution_phrase()
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let mut niceness = unsafe { let mut niceness = unsafe {
nix::errno::Errno::clear(); nix::errno::Errno::clear();
@ -109,6 +104,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::TrailingVarArg) .setting(AppSettings::TrailingVarArg)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.version(crate_version!()) .version(crate_version!())

View file

@ -14,13 +14,12 @@ use std::io::{stdin, BufRead, BufReader, Read};
use std::iter::repeat; use std::iter::repeat;
use std::path::Path; use std::path::Path;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
mod helper; mod helper;
static NAME: &str = "nl"; static NAME: &str = "nl";
static USAGE: &str = "nl [OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
// A regular expression matching everything.
// Settings store options used by nl to produce its output. // Settings store options used by nl to produce its output.
pub struct Settings { pub struct Settings {
@ -144,7 +143,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)

View file

@ -22,7 +22,7 @@ use std::os::unix::prelude::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{set_exit_code, UError, UResult}; use uucore::error::{set_exit_code, UError, UResult};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Run COMMAND ignoring hangup signals."; static ABOUT: &str = "Run COMMAND ignoring hangup signals.";
static LONG_HELP: &str = " static LONG_HELP: &str = "
@ -31,6 +31,9 @@ If standard output is terminal, it'll be appended to nohup.out instead,
or $HOME/nohup.out, if nohup.out open failed. or $HOME/nohup.out, if nohup.out open failed.
If standard error is terminal, it'll be redirected to stdout. If standard error is terminal, it'll be redirected to stdout.
"; ";
const USAGE: &str = "\
{} COMMAND [ARG]...
{} FLAG";
static NOHUP_OUT: &str = "nohup.out"; static NOHUP_OUT: &str = "nohup.out";
// exit codes that match the GNU implementation // exit codes that match the GNU implementation
static EXIT_CANCELED: i32 = 125; static EXIT_CANCELED: i32 = 125;
@ -83,12 +86,11 @@ impl Display for NohupError {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
replace_fds()?; replace_fds()?;
@ -119,6 +121,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.arg( .arg(
Arg::new(options::CMD) Arg::new(options::CMD)
.hide(true) .hide(true)
@ -205,13 +208,6 @@ fn find_stdout() -> UResult<File> {
} }
} }
fn usage() -> String {
format!(
"{0} COMMAND [ARG]...\n {0} FLAG",
uucore::execution_phrase()
)
}
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
extern "C" { extern "C" {
fn _vprocmgr_detach_from_console(flags: u32) -> *const libc::c_int; fn _vprocmgr_detach_from_console(flags: u32) -> *const libc::c_int;

View file

@ -11,6 +11,7 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::env; use std::env;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; pub const _SC_NPROCESSORS_CONF: libc::c_int = 83;
@ -25,15 +26,11 @@ static OPT_ALL: &str = "all";
static OPT_IGNORE: &str = "ignore"; static OPT_IGNORE: &str = "ignore";
static ABOUT: &str = "Print the number of cores available to the current process."; static ABOUT: &str = "Print the number of cores available to the current process.";
const USAGE: &str = "{} [OPTIONS]...";
fn usage() -> String {
format!("{0} [OPTIONS]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let mut ignore = match matches.value_of(OPT_IGNORE) { let mut ignore = match matches.value_of(OPT_IGNORE) {
Some(numstr) => match numstr.parse() { Some(numstr) => match numstr.parse() {
@ -75,6 +72,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_ALL) Arg::new(OPT_ALL)

View file

@ -15,6 +15,7 @@ use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use std::io::{BufRead, Write}; use std::io::{BufRead, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::format_usage;
use uucore::ranges::Range; use uucore::ranges::Range;
pub mod errors; pub mod errors;
@ -50,10 +51,7 @@ FIELDS supports cut(1) style field ranges:
- all fields - all fields
Multiple fields/ranges can be separated with commas Multiple fields/ranges can be separated with commas
"; ";
const USAGE: &str = "{} [OPTION]... [NUMBER]...";
fn usage() -> String {
format!("{0} [OPTION]... [NUMBER]...", uucore::execution_phrase())
}
fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: &NumfmtOptions) -> UResult<()> { fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: &NumfmtOptions) -> UResult<()> {
for l in args { for l in args {
@ -166,9 +164,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?; let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?;
@ -195,6 +191,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::AllowNegativeNumbers) .setting(AppSettings::AllowNegativeNumbers)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -45,15 +45,17 @@ use crate::prn_char::format_ascii_dump;
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
use uucore::parse_size::ParseSizeError; use uucore::parse_size::ParseSizeError;
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes
static ABOUT: &str = "dump files in octal and other formats"; static ABOUT: &str = "dump files in octal and other formats";
static USAGE: &str = r#"od [OPTION]... [--] [FILENAME]... static USAGE: &str = "\
od [-abcdDefFhHiIlLoOsxX] [FILENAME] [[+][0x]OFFSET[.][b]] {} [OPTION]... [--] [FILENAME]...
od --traditional [OPTION]... [FILENAME] [[+][0x]OFFSET[.][b] [[+][0x]LABEL[.][b]]]"#; {} [-abcdDefFhHiIlLoOsxX] [FILENAME] [[+][0x]OFFSET[.][b]]
{} --traditional [OPTION]... [FILENAME] [[+][0x]OFFSET[.][b] [[+][0x]LABEL[.][b]]]";
static LONG_HELP: &str = r#" static LONG_HELP: &str = r#"
Displays data in various human-readable formats. If multiple formats are Displays data in various human-readable formats. If multiple formats are
@ -289,7 +291,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.after_help(LONG_HELP) .after_help(LONG_HELP)
.setting( .setting(
AppSettings::TrailingVarArg | AppSettings::TrailingVarArg |

View file

@ -13,7 +13,7 @@ use std::fs;
use std::io::{ErrorKind, Write}; use std::io::{ErrorKind, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{set_exit_code, UResult, UUsageError}; use uucore::error::{set_exit_code, UResult, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
// operating mode // operating mode
enum Mode { enum Mode {
@ -24,6 +24,7 @@ enum Mode {
} }
static ABOUT: &str = "Check whether file names are valid or portable"; static ABOUT: &str = "Check whether file names are valid or portable";
const USAGE: &str = "{} [OPTION]... NAME...";
mod options { mod options {
pub const POSIX: &str = "posix"; pub const POSIX: &str = "posix";
@ -36,18 +37,13 @@ mod options {
const POSIX_PATH_MAX: usize = 256; const POSIX_PATH_MAX: usize = 256;
const POSIX_NAME_MAX: usize = 14; const POSIX_NAME_MAX: usize = 14;
fn usage() -> String {
format!("{0} [OPTION]... NAME...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
// set working mode // set working mode
let is_posix = matches.values_of(options::POSIX).is_some(); let is_posix = matches.values_of(options::POSIX).is_some();
@ -92,6 +88,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::POSIX) Arg::new(options::POSIX)

View file

@ -20,11 +20,12 @@ use std::os::unix::fs::MetadataExt;
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use std::path::PathBuf; use std::path::PathBuf;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
const BUFSIZE: usize = 1024; const BUFSIZE: usize = 1024;
static ABOUT: &str = "pinky - lightweight finger"; static ABOUT: &str = "pinky - lightweight finger";
const USAGE: &str = "{} [OPTION]... [USER]...";
mod options { mod options {
pub const LONG_FORMAT: &str = "long_format"; pub const LONG_FORMAT: &str = "long_format";
@ -39,10 +40,6 @@ mod options {
pub const USER: &str = "user"; pub const USER: &str = "user";
} }
fn usage() -> String {
format!("{0} [OPTION]... [USER]...", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
format!( format!(
"A lightweight 'finger' program; print user information.\n\ "A lightweight 'finger' program; print user information.\n\
@ -57,13 +54,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let users: Vec<String> = matches let users: Vec<String> = matches
.values_of(options::USER) .values_of(options::USER)
@ -136,6 +129,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::LONG_FORMAT) Arg::new(options::LONG_FORMAT)

View file

@ -9,23 +9,18 @@
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use std::env; use std::env;
use uucore::error::UResult; use uucore::{error::UResult, format_usage};
static ABOUT: &str = "Display the values of the specified environment VARIABLE(s), or (with no VARIABLE) display name and value pairs for them all."; static ABOUT: &str = "Display the values of the specified environment VARIABLE(s), or (with no VARIABLE) display name and value pairs for them all.";
const USAGE: &str = "{} [VARIABLE]... [OPTION]...";
static OPT_NULL: &str = "null"; static OPT_NULL: &str = "null";
static ARG_VARIABLES: &str = "variables"; static ARG_VARIABLES: &str = "variables";
fn usage() -> String {
format!("{0} [VARIABLE]... [OPTION]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let variables: Vec<String> = matches let variables: Vec<String> = matches
.values_of(ARG_VARIABLES) .values_of(ARG_VARIABLES)
@ -65,6 +60,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_NULL) Arg::new(OPT_NULL)

View file

@ -4,12 +4,12 @@
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::error::{UResult, UUsageError}; use uucore::error::{UResult, UUsageError};
use uucore::memo;
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
use uucore::{format_usage, memo};
const VERSION: &str = "version"; const VERSION: &str = "version";
const HELP: &str = "help"; const HELP: &str = "help";
const USAGE: &str = "printf FORMATSTRING [ARGUMENT]..."; const USAGE: &str = "{} FORMATSTRING [ARGUMENT]...";
const ABOUT: &str = "Print output based off of the format string and proceeding arguments."; const ABOUT: &str = "Print output based off of the format string and proceeding arguments.";
const AFTER_HELP: &str = " const AFTER_HELP: &str = "
basic anonymous string templating: basic anonymous string templating:
@ -294,7 +294,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.arg(Arg::new(HELP).long(HELP).help("Print help information")) .arg(Arg::new(HELP).long(HELP).help("Print help information"))
.arg( .arg(
Arg::new(VERSION) Arg::new(VERSION)

View file

@ -19,15 +19,17 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
use std::num::ParseIntError; use std::num::ParseIntError;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult}; use uucore::error::{FromIo, UError, UResult};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static NAME: &str = "ptx"; static NAME: &str = "ptx";
static BRIEF: &str = "Usage: ptx [OPTION]... [INPUT]... (without -G) or: \ const USAGE: &str = "\
ptx -G [OPTION]... [INPUT [OUTPUT]] \n Output a permuted index, \ {} [OPTION]... [INPUT]...
including context, of the words in the input files. \n\n Mandatory \ {} -G [OPTION]... [INPUT [OUTPUT]]";
arguments to long options are mandatory for short options too.\n
With no FILE, or when FILE is -, read standard input. \ const ABOUT: &str = "\
Default is '-F /'."; Output a permuted index, including context, of the words in the input files. \n\n\
Mandatory arguments to long options are mandatory for short options too.\n\
With no FILE, or when FILE is -, read standard input. Default is '-F /'.";
#[derive(Debug)] #[derive(Debug)]
enum OutFormat { enum OutFormat {
@ -703,8 +705,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.about(ABOUT)
.version(crate_version!()) .version(crate_version!())
.override_usage(BRIEF) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)

View file

@ -9,11 +9,13 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::env; use std::env;
use std::io; use std::io;
use std::path::PathBuf; use std::path::PathBuf;
use uucore::format_usage;
use uucore::display::println_verbatim; use uucore::display::println_verbatim;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
static ABOUT: &str = "Display the full filename of the current working directory."; static ABOUT: &str = "Display the full filename of the current working directory.";
const USAGE: &str = "{} [OPTION]... FILE...";
static OPT_LOGICAL: &str = "logical"; static OPT_LOGICAL: &str = "logical";
static OPT_PHYSICAL: &str = "physical"; static OPT_PHYSICAL: &str = "physical";
@ -120,15 +122,9 @@ fn logical_path() -> io::Result<PathBuf> {
} }
} }
fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let cwd = if matches.is_present(OPT_LOGICAL) { let cwd = if matches.is_present(OPT_LOGICAL) {
logical_path() logical_path()
} else { } else {
@ -156,6 +152,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_LOGICAL) Arg::new(OPT_LOGICAL)

View file

@ -16,9 +16,11 @@ use std::io::{stdout, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
const ABOUT: &str = "Print value of a symbolic link or canonical file name."; const ABOUT: &str = "Print value of a symbolic link or canonical file name.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
const OPT_CANONICALIZE: &str = "canonicalize"; const OPT_CANONICALIZE: &str = "canonicalize";
const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing"; const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing";
const OPT_CANONICALIZE_EXISTING: &str = "canonicalize-existing"; const OPT_CANONICALIZE_EXISTING: &str = "canonicalize-existing";
@ -30,14 +32,9 @@ const OPT_ZERO: &str = "zero";
const ARG_FILES: &str = "files"; const ARG_FILES: &str = "files";
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let mut no_newline = matches.is_present(OPT_NO_NEWLINE); let mut no_newline = matches.is_present(OPT_NO_NEWLINE);
let use_zero = matches.is_present(OPT_ZERO); let use_zero = matches.is_present(OPT_ZERO);
@ -102,6 +99,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_help(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_CANONICALIZE) Arg::new(OPT_CANONICALIZE)

View file

@ -18,10 +18,12 @@ use std::{
use uucore::{ use uucore::{
display::{print_verbatim, Quotable}, display::{print_verbatim, Quotable},
error::{FromIo, UResult}, error::{FromIo, UResult},
format_usage,
fs::{canonicalize, MissingHandling, ResolveMode}, fs::{canonicalize, MissingHandling, ResolveMode},
}; };
static ABOUT: &str = "print the resolved path"; static ABOUT: &str = "print the resolved path";
const USAGE: &str = "{} [OPTION]... FILE...";
static OPT_QUIET: &str = "quiet"; static OPT_QUIET: &str = "quiet";
static OPT_STRIP: &str = "strip"; static OPT_STRIP: &str = "strip";
@ -33,15 +35,9 @@ const OPT_CANONICALIZE_EXISTING: &str = "canonicalize-existing";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
/* the list of files */ /* the list of files */
@ -78,6 +74,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_QUIET) Arg::new(OPT_QUIET)

View file

@ -13,10 +13,11 @@ use std::path::{Path, PathBuf};
use uucore::display::println_verbatim; use uucore::display::println_verbatim;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Convert TO destination to the relative path from the FROM dir. static ABOUT: &str = "Convert TO destination to the relative path from the FROM dir.
If FROM path is omitted, current working dir will be used."; If FROM path is omitted, current working dir will be used.";
const USAGE: &str = "{} [-d DIR] TO [FROM]";
mod options { mod options {
pub const DIR: &str = "DIR"; pub const DIR: &str = "DIR";
@ -24,18 +25,13 @@ mod options {
pub const FROM: &str = "FROM"; pub const FROM: &str = "FROM";
} }
fn usage() -> String {
format!("{} [-d DIR] TO [FROM]", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = usage();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
let to = Path::new(matches.value_of(options::TO).unwrap()).to_path_buf(); // required let to = Path::new(matches.value_of(options::TO).unwrap()).to_path_buf(); // required
let from = match matches.value_of(options::FROM) { let from = match matches.value_of(options::FROM) {
@ -86,6 +82,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(options::DIR).short('d').takes_value(true).help( .arg(Arg::new(options::DIR).short('d').takes_value(true).help(
"If any of FROM and TO is not subpath of DIR, output absolute path instead of relative", "If any of FROM and TO is not subpath of DIR, output absolute path instead of relative",

View file

@ -19,6 +19,7 @@ use std::ops::BitOr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::format_usage;
use walkdir::{DirEntry, WalkDir}; use walkdir::{DirEntry, WalkDir};
#[derive(Eq, PartialEq, Clone, Copy)] #[derive(Eq, PartialEq, Clone, Copy)]
@ -40,6 +41,7 @@ struct Options {
} }
static ABOUT: &str = "Remove (unlink) the FILE(s)"; static ABOUT: &str = "Remove (unlink) the FILE(s)";
const USAGE: &str = "{} [OPTION]... FILE...";
static OPT_DIR: &str = "dir"; static OPT_DIR: &str = "dir";
static OPT_INTERACTIVE: &str = "interactive"; static OPT_INTERACTIVE: &str = "interactive";
static OPT_FORCE: &str = "force"; static OPT_FORCE: &str = "force";
@ -55,10 +57,6 @@ static PRESUME_INPUT_TTY: &str = "-presume-input-tty";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( String::from(
"By default, rm does not remove directories. Use the --recursive (-r or -R) "By default, rm does not remove directories. Use the --recursive (-r or -R)
@ -78,13 +76,9 @@ fn get_long_usage() -> String {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -149,6 +143,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_FORCE) Arg::new(OPT_FORCE)

View file

@ -16,24 +16,19 @@ use std::io;
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{set_exit_code, strip_errno, UResult}; use uucore::error::{set_exit_code, strip_errno, UResult};
use uucore::util_name; use uucore::{format_usage, util_name};
static ABOUT: &str = "Remove the DIRECTORY(ies), if they are empty."; static ABOUT: &str = "Remove the DIRECTORY(ies), if they are empty.";
const USAGE: &str = "{} [OPTION]... DIRECTORY...";
static OPT_IGNORE_FAIL_NON_EMPTY: &str = "ignore-fail-on-non-empty"; static OPT_IGNORE_FAIL_NON_EMPTY: &str = "ignore-fail-on-non-empty";
static OPT_PARENTS: &str = "parents"; static OPT_PARENTS: &str = "parents";
static OPT_VERBOSE: &str = "verbose"; static OPT_VERBOSE: &str = "verbose";
static ARG_DIRS: &str = "dirs"; static ARG_DIRS: &str = "dirs";
fn usage() -> String {
format!("{0} [OPTION]... DIRECTORY...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let opts = Opts { let opts = Opts {
ignore: matches.is_present(OPT_IGNORE_FAIL_NON_EMPTY), ignore: matches.is_present(OPT_IGNORE_FAIL_NON_EMPTY),
@ -179,6 +174,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(OPT_IGNORE_FAIL_NON_EMPTY) Arg::new(OPT_IGNORE_FAIL_NON_EMPTY)

View file

@ -4,6 +4,7 @@ use uucore::error::{UResult, UUsageError};
use clap::{App, AppSettings, Arg}; use clap::{App, AppSettings, Arg};
use selinux::{OpaqueSecurityContext, SecurityClass, SecurityContext}; use selinux::{OpaqueSecurityContext, SecurityClass, SecurityContext};
use uucore::format_usage;
use std::borrow::Cow; use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString}; use std::ffi::{CStr, CString, OsStr, OsString};
@ -18,6 +19,9 @@ use errors::{Error, Result, RunconError};
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
const ABOUT: &str = "Run command with specified security context."; const ABOUT: &str = "Run command with specified security context.";
const USAGE: &str = "\
{} [CONTEXT COMMAND [ARG...]]
{} [-c] [-u USER] [-r ROLE] [-t TYPE] [-l RANGE] COMMAND [ARG...]";
const DESCRIPTION: &str = "Run COMMAND with completely-specified CONTEXT, or with current or \ const DESCRIPTION: &str = "Run COMMAND with completely-specified CONTEXT, or with current or \
transitioned security context modified by one or more of \ transitioned security context modified by one or more of \
LEVEL, ROLE, TYPE, and USER.\n\n\ LEVEL, ROLE, TYPE, and USER.\n\n\
@ -36,19 +40,9 @@ pub mod options {
pub const RANGE: &str = "range"; pub const RANGE: &str = "range";
} }
fn get_usage() -> String {
format!(
"{0} [CONTEXT COMMAND [ARG...]]\n \
{0} [-c] [-u USER] [-r ROLE] [-t TYPE] [-l RANGE] COMMAND [ARG...]",
uucore::execution_phrase()
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let config = uu_app();
let config = uu_app().override_usage(usage.as_ref());
let options = match parse_command_line(config, args) { let options = match parse_command_line(config, args) {
Ok(r) => r, Ok(r) => r,
@ -114,6 +108,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.after_help(DESCRIPTION) .after_help(DESCRIPTION)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::COMPUTE) Arg::new(options::COMPUTE)

View file

@ -12,6 +12,7 @@ use num_traits::Zero;
use uucore::error::FromIo; use uucore::error::FromIo;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::format_usage;
use uucore::memo::Memo; use uucore::memo::Memo;
use uucore::show; use uucore::show;
@ -27,6 +28,10 @@ use crate::number::Number;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
static ABOUT: &str = "Display numbers from FIRST to LAST, in steps of INCREMENT."; static ABOUT: &str = "Display numbers from FIRST to LAST, in steps of INCREMENT.";
const USAGE: &str = "\
{} [OPTION]... LAST
{} [OPTION]... FIRST LAST
{} [OPTION]... FIRST INCREMENT LAST";
static OPT_SEPARATOR: &str = "separator"; static OPT_SEPARATOR: &str = "separator";
static OPT_TERMINATOR: &str = "terminator"; static OPT_TERMINATOR: &str = "terminator";
static OPT_WIDTHS: &str = "widths"; static OPT_WIDTHS: &str = "widths";
@ -34,14 +39,6 @@ static OPT_FORMAT: &str = "format";
static ARG_NUMBERS: &str = "numbers"; static ARG_NUMBERS: &str = "numbers";
fn usage() -> String {
format!(
"{0} [OPTION]... LAST
{0} [OPTION]... FIRST LAST
{0} [OPTION]... FIRST INCREMENT LAST",
uucore::execution_phrase()
)
}
#[derive(Clone)] #[derive(Clone)]
struct SeqOptions<'a> { struct SeqOptions<'a> {
separator: String, separator: String,
@ -62,8 +59,7 @@ type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal);
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::<Vec<_>>(); let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::<Vec<_>>();
@ -152,6 +148,7 @@ pub fn uu_app<'a>() -> App<'a> {
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.arg( .arg(
Arg::new(OPT_SEPARATOR) Arg::new(OPT_SEPARATOR)
.short('s') .short('s')

View file

@ -20,7 +20,7 @@ use std::io::SeekFrom;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::{util_name, InvalidEncodingHandling}; use uucore::{format_usage, util_name, InvalidEncodingHandling};
#[macro_use] #[macro_use]
extern crate uucore; extern crate uucore;
@ -214,10 +214,7 @@ impl<'a> BytesGenerator<'a> {
static ABOUT: &str = "Overwrite the specified FILE(s) repeatedly, in order to make it harder\n\ static ABOUT: &str = "Overwrite the specified FILE(s) repeatedly, in order to make it harder\n\
for even very expensive hardware probing to recover the data. for even very expensive hardware probing to recover the data.
"; ";
const USAGE: &str = "{} [OPTION]... FILE...";
fn usage() -> String {
format!("{} [OPTION]... FILE...", uucore::execution_phrase())
}
static AFTER_HELP: &str = static AFTER_HELP: &str =
"Delete FILE(s) if --remove (-u) is specified. The default is not to remove\n\ "Delete FILE(s) if --remove (-u) is specified. The default is not to remove\n\
@ -273,11 +270,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage(); let matches = uu_app().get_matches_from(args);
let app = uu_app().override_usage(&usage[..]);
let matches = app.get_matches_from(args);
if !matches.is_present(options::FILE) { if !matches.is_present(options::FILE) {
return Err(UUsageError::new(1, "missing file operand")); return Err(UUsageError::new(1, "missing file operand"));
@ -326,6 +319,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FORCE) Arg::new(options::FORCE)

View file

@ -14,7 +14,7 @@ use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::{execution_phrase, InvalidEncodingHandling}; use uucore::{format_usage, InvalidEncodingHandling};
mod rand_read_adapter; mod rand_read_adapter;
@ -25,10 +25,14 @@ enum Mode {
} }
static NAME: &str = "shuf"; static NAME: &str = "shuf";
static USAGE: &str = r#"shuf [OPTION]... [FILE] static USAGE: &str = "\
or: shuf -e [OPTION]... [ARG]... {} [OPTION]... [FILE]
or: shuf -i LO-HI [OPTION]..."#; {} -e [OPTION]... [ARG]...
static ABOUT: &str = "Shuffle the input by outputting a random permutation of input lines. Each output permutation is equally likely."; {} -i LO-HI [OPTION]...";
static ABOUT: &str = "\
Shuffle the input by outputting a random permutation of input lines.\
Each output permutation is equally likely.\
With no FILE, or when FILE is -, read standard input.";
struct Options { struct Options {
head_count: usize, head_count: usize,
@ -55,9 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let matches = uu_app() let matches = uu_app().get_matches_from(args);
.override_usage(&USAGE.replace(NAME, execution_phrase())[..])
.get_matches_from(args);
let mode = if let Some(args) = matches.values_of(options::ECHO) { let mode = if let Some(args) = matches.values_of(options::ECHO) {
Mode::Echo(args.map(String::from).collect()) Mode::Echo(args.map(String::from).collect())
@ -122,7 +124,7 @@ pub fn uu_app<'a>() -> App<'a> {
.name(NAME) .name(NAME)
.about(ABOUT) .about(ABOUT)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ECHO) Arg::new(options::ECHO)

View file

@ -8,11 +8,17 @@
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use uucore::error::{UResult, USimpleError}; use uucore::{
error::{UResult, USimpleError},
format_usage,
};
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
static ABOUT: &str = "Pause for NUMBER seconds."; static ABOUT: &str = "Pause for NUMBER seconds.";
const USAGE: &str = "\
{} NUMBER[SUFFIX]...
{} OPTION";
static LONG_HELP: &str = "Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default), static LONG_HELP: &str = "Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default),
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations 'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
that require NUMBER be an integer, here NUMBER may be an arbitrary floating that require NUMBER be an integer, here NUMBER may be an arbitrary floating
@ -23,19 +29,9 @@ mod options {
pub const NUMBER: &str = "NUMBER"; pub const NUMBER: &str = "NUMBER";
} }
fn usage() -> String {
format!(
"{0} {1}[SUFFIX]... \n {0} OPTION",
uucore::execution_phrase(),
options::NUMBER
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
if let Some(values) = matches.values_of(options::NUMBER) { if let Some(values) = matches.values_of(options::NUMBER) {
let numbers = values.collect::<Vec<_>>(); let numbers = values.collect::<Vec<_>>();
@ -50,6 +46,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::NUMBER) Arg::new(options::NUMBER)

View file

@ -49,11 +49,14 @@ use uucore::display::Quotable;
use uucore::error::{set_exit_code, strip_errno, UError, UResult, USimpleError, UUsageError}; use uucore::error::{set_exit_code, strip_errno, UError, UResult, USimpleError, UUsageError};
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::version_cmp::version_cmp; use uucore::version_cmp::version_cmp;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
use crate::tmp_dir::TmpDirWrapper; use crate::tmp_dir::TmpDirWrapper;
const ABOUT: &str = "Display sorted concatenation of all FILE(s)."; const ABOUT: &str = "\
Display sorted concatenation of all FILE(s).\
With no FILE, or when FILE is -, read standard input.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
const LONG_HELP_KEYS: &str = "The key format is FIELD[.CHAR][OPTIONS][,FIELD[.CHAR]][OPTIONS]. const LONG_HELP_KEYS: &str = "The key format is FIELD[.CHAR][OPTIONS][,FIELD[.CHAR]][OPTIONS].
@ -1030,16 +1033,6 @@ impl FieldSelector {
} }
} }
fn usage() -> String {
format!(
"{0} [OPTION]... [FILE]...
Write the sorted concatenation of all FILE(s) to standard output.
Mandatory arguments for long options are mandatory for short options too.
With no FILE, or when FILE is -, read standard input.",
uucore::execution_phrase()
)
}
/// Creates an `Arg` that conflicts with all other sort modes. /// Creates an `Arg` that conflicts with all other sort modes.
fn make_sort_mode_arg<'a>(mode: &'a str, short: char, help: &'a str) -> Arg<'a> { fn make_sort_mode_arg<'a>(mode: &'a str, short: char, help: &'a str) -> Arg<'a> {
let mut arg = Arg::new(mode).short(short).long(mode).help(help); let mut arg = Arg::new(mode).short(short).long(mode).help(help);
@ -1056,13 +1049,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage();
let mut settings: GlobalSettings = Default::default(); let mut settings: GlobalSettings = Default::default();
let matches = match uu_app() let matches = match uu_app().try_get_matches_from(args) {
.override_usage(&usage[..])
.try_get_matches_from(args)
{
Ok(t) => t, Ok(t) => t,
Err(e) => { Err(e) => {
// not all clap "Errors" are because of a failure to parse arguments. // not all clap "Errors" are because of a failure to parse arguments.
@ -1276,6 +1265,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::modes::SORT) Arg::new(options::modes::SORT)

View file

@ -22,6 +22,7 @@ use std::num::ParseIntError;
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::uio_error; use uucore::uio_error;
@ -44,32 +45,15 @@ static OPT_ELIDE_EMPTY_FILES: &str = "elide-empty-files";
static ARG_INPUT: &str = "input"; static ARG_INPUT: &str = "input";
static ARG_PREFIX: &str = "prefix"; static ARG_PREFIX: &str = "prefix";
fn usage() -> String { const USAGE: &str = "{} [OPTION]... [INPUT [PREFIX]]";
format!( const AFTER_HELP: &str = "\
"{0} [OPTION]... [INPUT [PREFIX]]", Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default \
uucore::execution_phrase() size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is \
) -, read standard input.";
}
fn get_long_usage() -> String {
format!(
"Usage:
{0}
Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default
size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is
-, read standard input.",
usage()
)
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let long_usage = get_long_usage();
let matches = uu_app()
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
match Settings::from(&matches) { match Settings::from(&matches) {
Ok(settings) => split(&settings), Ok(settings) => split(&settings),
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{}", e))), Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{}", e))),
@ -81,6 +65,8 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about("Create output files containing consecutive or interleaved sections of input") .about("Create output files containing consecutive or interleaved sections of input")
.after_help(AFTER_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
// strategy (mutually exclusive) // strategy (mutually exclusive)
.arg( .arg(

View file

@ -8,13 +8,13 @@
#[macro_use] #[macro_use]
extern crate uucore; extern crate uucore;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::entries;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::fs::display_permissions; use uucore::fs::display_permissions;
use uucore::fsext::{ use uucore::fsext::{
pretty_filetype, pretty_fstype, pretty_time, read_fs_list, statfs, BirthTime, FsMeta, pretty_filetype, pretty_fstype, pretty_time, read_fs_list, statfs, BirthTime, FsMeta,
}; };
use uucore::libc::mode_t; use uucore::libc::mode_t;
use uucore::{entries, format_usage};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use std::borrow::Cow; use std::borrow::Cow;
@ -87,6 +87,7 @@ macro_rules! print_adjusted {
} }
static ABOUT: &str = "Display file or file system status."; static ABOUT: &str = "Display file or file system status.";
const USAGE: &str = "{} [OPTION]... FILE...";
pub mod options { pub mod options {
pub static DEREFERENCE: &str = "dereference"; pub static DEREFERENCE: &str = "dereference";
@ -893,10 +894,6 @@ impl Stater {
} }
} }
fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( String::from(
" "
@ -957,13 +954,9 @@ for details about the options it supports.
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
let stater = Stater::new(&matches)?; let stater = Stater::new(&matches)?;
let exit_status = stater.exec(); let exit_status = stater.exec();
@ -978,6 +971,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::DEREFERENCE) Arg::new(options::DEREFERENCE)

View file

@ -21,11 +21,12 @@ use tempfile::tempdir;
use tempfile::TempDir; use tempfile::TempDir;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::parse_size::parse_size; use uucore::parse_size::parse_size;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = static ABOUT: &str =
"Run COMMAND, with modified buffering operations for its standard streams.\n\n\ "Run COMMAND, with modified buffering operations for its standard streams.\n\n\
Mandatory arguments to long options are mandatory for short options too."; Mandatory arguments to long options are mandatory for short options too.";
const USAGE: &str = "{} OPTION... COMMAND";
static LONG_HELP: &str = "If MODE is 'L' the corresponding stream will be line buffered.\n\ static LONG_HELP: &str = "If MODE is 'L' the corresponding stream will be line buffered.\n\
This option is invalid with standard input.\n\n\ This option is invalid with standard input.\n\n\
If MODE is '0' the corresponding stream will be unbuffered.\n\n\ If MODE is '0' the corresponding stream will be unbuffered.\n\n\
@ -48,10 +49,6 @@ mod options {
pub const COMMAND: &str = "command"; pub const COMMAND: &str = "command";
} }
fn usage() -> String {
format!("{0} OPTION... COMMAND", uucore::execution_phrase())
}
const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so"));
enum BufferType { enum BufferType {
@ -154,9 +151,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage();
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let matches = uu_app().get_matches_from(args);
let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?; let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?;
@ -196,6 +192,7 @@ pub fn uu_app<'a>() -> App<'a> {
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.override_usage(format_usage(USAGE))
.setting(AppSettings::TrailingVarArg) .setting(AppSettings::TrailingVarArg)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -16,10 +16,10 @@ use std::io::{stdin, Read};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static NAME: &str = "sum"; static NAME: &str = "sum";
static USAGE: &str = "sum [OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
static SUMMARY: &str = "Checksum and count the blocks in a file.\n\ static SUMMARY: &str = "Checksum and count the blocks in a file.\n\
With no FILE, or when FILE is -, read standard input."; With no FILE, or when FILE is -, read standard input.";
@ -144,7 +144,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -13,8 +13,10 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
static ABOUT: &str = "Synchronize cached writes to persistent storage"; static ABOUT: &str = "Synchronize cached writes to persistent storage";
const USAGE: &str = "{} [OPTION]... FILE...";
pub mod options { pub mod options {
pub static FILE_SYSTEM: &str = "file-system"; pub static FILE_SYSTEM: &str = "file-system";
pub static DATA: &str = "data"; pub static DATA: &str = "data";
@ -157,15 +159,9 @@ mod platform {
} }
} }
fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -198,6 +194,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::FILE_SYSTEM) Arg::new(options::FILE_SYSTEM)

View file

@ -19,13 +19,13 @@ use std::{
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UError; use uucore::error::UError;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::show;
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
use uucore::{format_usage, show};
use crate::error::TacError; use crate::error::TacError;
static NAME: &str = "tac"; static NAME: &str = "tac";
static USAGE: &str = "[OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
static SUMMARY: &str = "Write each file to standard output, last line first."; static SUMMARY: &str = "Write each file to standard output, last line first.";
mod options { mod options {
@ -64,7 +64,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -31,6 +31,7 @@ use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use uucore::lines::lines; use uucore::lines::lines;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::ringbuffer::RingBuffer; use uucore::ringbuffer::RingBuffer;
@ -47,7 +48,7 @@ const ABOUT: &str = "\
\n\ \n\
Mandatory arguments to long flags are mandatory for short flags too.\ Mandatory arguments to long flags are mandatory for short flags too.\
"; ";
const USAGE: &str = "tail [FLAG]... [FILE]..."; const USAGE: &str = "{} [FLAG]... [FILE]...";
pub mod options { pub mod options {
pub mod verbosity { pub mod verbosity {
@ -277,7 +278,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::BYTES) Arg::new(options::BYTES)

View file

@ -15,11 +15,13 @@ use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write};
use std::path::PathBuf; use std::path::PathBuf;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::format_usage;
#[cfg(unix)] #[cfg(unix)]
use uucore::libc; use uucore::libc;
static ABOUT: &str = "Copy standard input to each FILE, and also to standard output."; static ABOUT: &str = "Copy standard input to each FILE, and also to standard output.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
mod options { mod options {
pub const APPEND: &str = "append"; pub const APPEND: &str = "append";
@ -34,15 +36,9 @@ struct Options {
files: Vec<String>, files: Vec<String>,
} }
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let options = Options { let options = Options {
append: matches.is_present(options::APPEND), append: matches.is_present(options::APPEND),
@ -63,6 +59,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.after_help("If a FILE is -, it refers to a file named - .") .after_help("If a FILE is -, it refers to a file named - .")
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -15,12 +15,14 @@ use parser::{parse, Operator, Symbol, UnaryOperator};
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
const USAGE: &str = "test EXPRESSION const USAGE: &str = "\
or: test {} EXPRESSION
or: [ EXPRESSION ] {}
or: [ ] [ EXPRESSION ]
or: [ OPTION"; [ ]
[ OPTION";
// We use after_help so that this comes after the usage string (it would come before if we used about) // We use after_help so that this comes after the usage string (it would come before if we used about)
const AFTER_HELP: &str = " const AFTER_HELP: &str = "
@ -92,7 +94,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
} }
@ -109,7 +111,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
App::new(binary_name) App::new(binary_name)
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
// Disable printing of -h and -v as valid alternatives for --help and --version, // Disable printing of -h and -v as valid alternatives for --help and --version,
// since we don't recognize -h and -v as help/version flags. // since we don't recognize -h and -v as help/version flags.

View file

@ -20,16 +20,10 @@ use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::process::ChildExt; use uucore::process::ChildExt;
use uucore::signals::{signal_by_name_or_value, signal_name_by_value}; use uucore::signals::{signal_by_name_or_value, signal_name_by_value};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION.";
const USAGE: &str = "{} [OPTION] DURATION COMMAND...";
fn usage() -> String {
format!(
"{0} [OPTION] DURATION COMMAND...",
uucore::execution_phrase()
)
}
const ERR_EXIT_STATUS: i32 = 125; const ERR_EXIT_STATUS: i32 = 125;
@ -106,9 +100,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = usage(); let app = uu_app();
let app = uu_app().override_usage(&usage[..]);
let matches = app.get_matches_from(args); let matches = app.get_matches_from(args);
@ -128,6 +120,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new("timeout") App::new("timeout")
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.arg( .arg(
Arg::new(options::FOREGROUND) Arg::new(options::FOREGROUND)
.long(options::FOREGROUND) .long(options::FOREGROUND)

View file

@ -19,8 +19,10 @@ use std::fs::{self, File};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError}; use uucore::error::{FromIo, UError, UResult, USimpleError};
use uucore::format_usage;
static ABOUT: &str = "Update the access and modification times of each FILE to the current time."; static ABOUT: &str = "Update the access and modification times of each FILE to the current time.";
const USAGE: &str = "{} [OPTION]... [USER]";
pub mod options { pub mod options {
// Both SOURCES and sources are needed as we need to be able to refer to the ArgGroup. // Both SOURCES and sources are needed as we need to be able to refer to the ArgGroup.
pub static SOURCES: &str = "sources"; pub static SOURCES: &str = "sources";
@ -48,15 +50,9 @@ fn local_tm_to_filetime(tm: time::Tm) -> FileTime {
FileTime::from_unix_time(ts.sec as i64, ts.nsec as u32) FileTime::from_unix_time(ts.sec as i64, ts.nsec as u32)
} }
fn usage() -> String {
format!("{0} [OPTION]... [USER]", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let files = matches.values_of_os(ARG_FILES).ok_or_else(|| { let files = matches.values_of_os(ARG_FILES).ok_or_else(|| {
USimpleError::new( USimpleError::new(
@ -149,6 +145,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ACCESS) Arg::new(options::ACCESS)

View file

@ -15,13 +15,14 @@ use clap::{crate_version, App, AppSettings, Arg};
use nom::AsBytes; use nom::AsBytes;
use operation::{translate_input, Sequence, SqueezeOperation, TranslateOperation}; use operation::{translate_input, Sequence, SqueezeOperation, TranslateOperation};
use std::io::{stdin, stdout, BufReader, BufWriter}; use std::io::{stdin, stdout, BufReader, BufWriter};
use uucore::show; use uucore::{format_usage, show};
use crate::operation::DeleteOperation; use crate::operation::DeleteOperation;
use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::{display::Quotable, InvalidEncodingHandling}; use uucore::{display::Quotable, InvalidEncodingHandling};
static ABOUT: &str = "translate or delete characters"; static ABOUT: &str = "translate or delete characters";
const USAGE: &str = "{} [OPTION]... SET1 [SET2]";
mod options { mod options {
pub const COMPLEMENT: &str = "complement"; pub const COMPLEMENT: &str = "complement";
@ -31,10 +32,6 @@ mod options {
pub const SETS: &str = "sets"; pub const SETS: &str = "sets";
} }
fn get_usage() -> String {
format!("{} [OPTION]... SET1 [SET2]", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
"Translate, squeeze, and/or delete characters from standard input, \ "Translate, squeeze, and/or delete characters from standard input, \
writing to standard output." writing to standard output."
@ -47,13 +44,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let delete_flag = matches.is_present(options::DELETE); let delete_flag = matches.is_present(options::DELETE);
let complement_flag = matches.is_present(options::COMPLEMENT); let complement_flag = matches.is_present(options::COMPLEMENT);
@ -148,6 +141,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(

View file

@ -15,6 +15,7 @@ use std::os::unix::fs::FileTypeExt;
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
@ -74,6 +75,7 @@ impl TruncateMode {
} }
static ABOUT: &str = "Shrink or extend the size of each file to the specified size."; static ABOUT: &str = "Shrink or extend the size of each file to the specified size.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
pub mod options { pub mod options {
pub static IO_BLOCKS: &str = "io-blocks"; pub static IO_BLOCKS: &str = "io-blocks";
@ -83,10 +85,6 @@ pub mod options {
pub static ARG_FILES: &str = "files"; pub static ARG_FILES: &str = "files";
} }
fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( String::from(
" "
@ -111,11 +109,9 @@ fn get_long_usage() -> String {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
.override_usage(&usage[..])
.after_help(&long_usage[..]) .after_help(&long_usage[..])
.try_get_matches_from(args) .try_get_matches_from(args)
.map_err(|e| { .map_err(|e| {
@ -146,6 +142,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::IO_BLOCKS) Arg::new(options::IO_BLOCKS)

View file

@ -12,7 +12,7 @@ use std::io::{stdin, BufRead, BufReader, Read};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static SUMMARY: &str = "Topological sort the strings in FILE. static SUMMARY: &str = "Topological sort the strings in FILE.
Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline). Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline).
@ -96,7 +96,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(options::FILE).default_value("-").hide(true)) .arg(Arg::new(options::FILE).default_value("-").hide(true))

View file

@ -13,27 +13,22 @@ use clap::{crate_version, App, AppSettings, Arg};
use std::ffi::CStr; use std::ffi::CStr;
use std::io::Write; use std::io::Write;
use uucore::error::{UResult, UUsageError}; use uucore::error::{UResult, UUsageError};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static ABOUT: &str = "Print the file name of the terminal connected to standard input."; static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
const USAGE: &str = "{} [OPTION]...";
mod options { mod options {
pub const SILENT: &str = "silent"; pub const SILENT: &str = "silent";
} }
fn usage() -> String {
format!("{0} [OPTION]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let matches = uu_app() let matches = uu_app()
.override_usage(&usage[..])
.try_get_matches_from(args) .try_get_matches_from(args)
.map_err(|e| UUsageError::new(2, format!("{}", e)))?; .map_err(|e| UUsageError::new(2, format!("{}", e)))?;
@ -75,6 +70,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::SILENT) Arg::new(options::SILENT)

View file

@ -12,9 +12,13 @@
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use platform_info::*; use platform_info::*;
use uucore::error::{FromIo, UResult}; use uucore::{
error::{FromIo, UResult},
format_usage,
};
const ABOUT: &str = "Print certain system information. With no OPTION, same as -s."; const ABOUT: &str = "Print certain system information. With no OPTION, same as -s.";
const USAGE: &str = "{} [OPTION]...";
pub mod options { pub mod options {
pub static ALL: &str = "all"; pub static ALL: &str = "all";
@ -49,8 +53,7 @@ const HOST_OS: &str = "Redox";
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = format!("{} [OPTION]...", uucore::execution_phrase()); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let uname = let uname =
PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?; PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?;
@ -122,6 +125,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(options::ALL) .arg(Arg::new(options::ALL)
.short('a') .short('a')

View file

@ -18,10 +18,10 @@ use std::str::from_utf8;
use unicode_width::UnicodeWidthChar; use unicode_width::UnicodeWidthChar;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
static NAME: &str = "unexpand"; static NAME: &str = "unexpand";
static USAGE: &str = "unexpand [OPTION]... [FILE]..."; static USAGE: &str = "{} [OPTION]... [FILE]...";
static SUMMARY: &str = "Convert blanks in each FILE to tabs, writing to standard output.\n\ static SUMMARY: &str = "Convert blanks in each FILE to tabs, writing to standard output.\n\
With no FILE, or when FILE is -, read standard input."; With no FILE, or when FILE is -, read standard input.";
@ -106,7 +106,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.override_usage(USAGE) .override_usage(format_usage(USAGE))
.about(SUMMARY) .about(SUMMARY)
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(options::FILE).hide(true).multiple_occurrences(true)) .arg(Arg::new(options::FILE).hide(true).multiple_occurrences(true))

View file

@ -13,8 +13,10 @@ use std::str::FromStr;
use strum_macros::{AsRefStr, EnumString}; use strum_macros::{AsRefStr, EnumString};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError}; use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
static ABOUT: &str = "Report or omit repeated lines."; static ABOUT: &str = "Report or omit repeated lines.";
const USAGE: &str = "{} [OPTION]... [INPUT [OUTPUT]]...";
pub mod options { pub mod options {
pub static ALL_REPEATED: &str = "all-repeated"; pub static ALL_REPEATED: &str = "all-repeated";
pub static CHECK_CHARS: &str = "check-chars"; pub static CHECK_CHARS: &str = "check-chars";
@ -239,13 +241,6 @@ fn opt_parsed<T: FromStr>(opt_name: &str, matches: &ArgMatches) -> UResult<Optio
}) })
} }
fn usage() -> String {
format!(
"{0} [OPTION]... [INPUT [OUTPUT]]...",
uucore::execution_phrase()
)
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( String::from(
"Filter adjacent matching lines from INPUT (or standard input),\n\ "Filter adjacent matching lines from INPUT (or standard input),\n\
@ -257,13 +252,9 @@ fn get_long_usage() -> String {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -303,6 +294,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ALL_REPEATED) Arg::new(options::ALL_REPEATED)

View file

@ -11,6 +11,7 @@
use chrono::{Local, TimeZone, Utc}; use chrono::{Local, TimeZone, Utc};
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::format_usage;
// import crate time from utmpx // import crate time from utmpx
pub use uucore::libc; pub use uucore::libc;
use uucore::libc::time_t; use uucore::libc::time_t;
@ -20,6 +21,7 @@ use uucore::error::{UResult, USimpleError};
static ABOUT: &str = "Display the current time, the length of time the system has been up,\n\ static ABOUT: &str = "Display the current time, the length of time the system has been up,\n\
the number of users on the system, and the average number of jobs\n\ the number of users on the system, and the average number of jobs\n\
in the run queue over the last 1, 5 and 15 minutes."; in the run queue over the last 1, 5 and 15 minutes.";
const USAGE: &str = "{} [OPTION]...";
pub mod options { pub mod options {
pub static SINCE: &str = "since"; pub static SINCE: &str = "since";
} }
@ -32,14 +34,9 @@ extern "C" {
fn GetTickCount() -> uucore::libc::uint32_t; fn GetTickCount() -> uucore::libc::uint32_t;
} }
fn usage() -> String {
format!("{0} [OPTION]...", uucore::execution_phrase())
}
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let (boot_time, user_count) = process_utmpx(); let (boot_time, user_count) = process_utmpx();
let uptime = get_uptime(boot_time); let uptime = get_uptime(boot_time);
@ -66,6 +63,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::SINCE) Arg::new(options::SINCE)

View file

@ -12,16 +12,14 @@ use std::path::Path;
use clap::{crate_version, App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use uucore::error::UResult; use uucore::error::UResult;
use uucore::format_usage;
use uucore::utmpx::{self, Utmpx}; use uucore::utmpx::{self, Utmpx};
static ABOUT: &str = "Print the user names of users currently logged in to the current host"; static ABOUT: &str = "Print the user names of users currently logged in to the current host";
const USAGE: &str = "{} [FILE]";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String {
format!("{0} [FILE]", uucore::execution_phrase())
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
format!( format!(
"Output who is currently logged in according to FILE. "Output who is currently logged in according to FILE.
@ -32,13 +30,9 @@ If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let files: Vec<&Path> = matches let files: Vec<&Path> = matches
.values_of_os(ARG_FILES) .values_of_os(ARG_FILES)
@ -68,6 +62,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg(Arg::new(ARG_FILES).takes_value(true).max_values(1)) .arg(Arg::new(ARG_FILES).takes_value(true).max_values(1))
} }

View file

@ -15,6 +15,7 @@ use count_fast::{count_bytes_and_lines_fast, count_bytes_fast};
use countable::WordCountable; use countable::WordCountable;
use unicode_width::UnicodeWidthChar; use unicode_width::UnicodeWidthChar;
use utf8::{BufReadDecoder, BufReadDecoderError}; use utf8::{BufReadDecoder, BufReadDecoderError};
use uucore::format_usage;
use word_count::{TitledWordCount, WordCount}; use word_count::{TitledWordCount, WordCount};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
@ -81,7 +82,8 @@ impl Settings {
} }
static ABOUT: &str = "Display newline, word, and byte counts for each FILE, and a total line if static ABOUT: &str = "Display newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified."; more than one FILE is specified. With no FILE, or when FILE is -, read standard input.";
const USAGE: &str = "{} [OPTION]... [FILE]...";
pub mod options { pub mod options {
pub static BYTES: &str = "bytes"; pub static BYTES: &str = "bytes";
@ -95,14 +97,6 @@ pub mod options {
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
static STDIN_REPR: &str = "-"; static STDIN_REPR: &str = "-";
fn usage() -> String {
format!(
"{0} [OPTION]... [FILE]...
With no FILE, or when FILE is -, read standard input.",
uucore::execution_phrase()
)
}
enum StdinKind { enum StdinKind {
/// Stdin specified on command-line with "-". /// Stdin specified on command-line with "-".
Explicit, Explicit,
@ -180,9 +174,7 @@ impl Display for WcError {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let matches = uu_app().get_matches_from(args);
let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let inputs = inputs(&matches)?; let inputs = inputs(&matches)?;
@ -195,6 +187,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::BYTES) Arg::new(options::BYTES)

View file

@ -17,7 +17,7 @@ use std::borrow::Cow;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::PathBuf; use std::path::PathBuf;
use uucore::InvalidEncodingHandling; use uucore::{format_usage, InvalidEncodingHandling};
mod options { mod options {
pub const ALL: &str = "all"; pub const ALL: &str = "all";
@ -38,19 +38,13 @@ mod options {
} }
static ABOUT: &str = "Print information about users who are currently logged in."; static ABOUT: &str = "Print information about users who are currently logged in.";
const USAGE: &str = "{} [OPTION]... [ FILE | ARG1 ARG2 ]";
#[cfg(any(target_os = "linux"))] #[cfg(any(target_os = "linux"))]
static RUNLEVEL_HELP: &str = "print current runlevel"; static RUNLEVEL_HELP: &str = "print current runlevel";
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)";
fn usage() -> String {
format!(
"{0} [OPTION]... [ FILE | ARG1 ARG2 ]",
uucore::execution_phrase()
)
}
fn get_long_usage() -> String { fn get_long_usage() -> String {
format!( format!(
"If FILE is not specified, use {}. /var/log/wtmp as FILE is common.\n\ "If FILE is not specified, use {}. /var/log/wtmp as FILE is common.\n\
@ -65,13 +59,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app().after_help(&after_help[..]).get_matches_from(args);
.override_usage(&usage[..])
.after_help(&after_help[..])
.get_matches_from(args);
let files: Vec<String> = matches let files: Vec<String> = matches
.values_of(options::FILE) .values_of(options::FILE)
@ -165,6 +155,7 @@ pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
.arg( .arg(
Arg::new(options::ALL) Arg::new(options::ALL)

View file

@ -15,10 +15,13 @@ extern crate clap;
use clap::{App, AppSettings, Arg}; use clap::{App, AppSettings, Arg};
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
mod splice; mod splice;
const USAGE: &str = "{} [STRING]...";
// it's possible that using a smaller or larger buffer might provide better performance on some // it's possible that using a smaller or larger buffer might provide better performance on some
// systems, but honestly this is good enough // systems, but honestly this is good enough
const BUF_SIZE: usize = 16 * 1024; const BUF_SIZE: usize = 16 * 1024;
@ -48,6 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app<'a>() -> App<'a> { pub fn uu_app<'a>() -> App<'a> {
app_from_crate!() app_from_crate!()
.override_usage(format_usage(USAGE))
.arg(Arg::new("STRING").index(1).multiple_occurrences(true)) .arg(Arg::new("STRING").index(1).multiple_occurrences(true))
.setting(AppSettings::InferLongArgs) .setting(AppSettings::InferLongArgs)
} }

View file

@ -94,6 +94,15 @@ macro_rules! bin {
}; };
} }
/// Generate the usage string for clap.
///
/// This function replaces all occurrences of `{}` with the execution phrase
/// and leaks the result to return a `&'static str`. It does **not** support
/// more advanced formatting features such as `{0}`.
pub fn format_usage(s: &str) -> &'static str {
&*Box::leak(s.replace("{}", crate::execution_phrase()).into_boxed_str())
}
pub fn get_utility_is_second_arg() -> bool { pub fn get_utility_is_second_arg() -> bool {
crate::macros::UTILITY_IS_SECOND_ARG.load(Ordering::SeqCst) crate::macros::UTILITY_IS_SECOND_ARG.load(Ordering::SeqCst)
} }