mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 01:17:09 +00:00
fix -h and --help discrepancies
addresses https://github.com/uutils/coreutils/issues/3370
This commit is contained in:
parent
b70a61aa11
commit
88752ecc3e
7 changed files with 46 additions and 37 deletions
|
@ -469,14 +469,25 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let matches = uu_app()
|
let after_help = &*format!(
|
||||||
.after_help(&*format!(
|
|
||||||
"{}\n{}",
|
"{}\n{}",
|
||||||
LONG_HELP,
|
LONG_HELP,
|
||||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||||
))
|
);
|
||||||
.try_get_matches_from(args)?;
|
let matches = uu_app().after_help(after_help).try_get_matches_from(args);
|
||||||
|
|
||||||
|
// The error is parsed here because we do not want version or help being printed to stderr.
|
||||||
|
if let Err(e) = matches {
|
||||||
|
let mut app = uu_app().after_help(after_help);
|
||||||
|
|
||||||
|
match e.kind() {
|
||||||
|
clap::ErrorKind::DisplayHelp => {
|
||||||
|
app.print_help()?;
|
||||||
|
}
|
||||||
|
clap::ErrorKind::DisplayVersion => println!("{}", app.render_version()),
|
||||||
|
_ => return Err(Box::new(e)),
|
||||||
|
};
|
||||||
|
} else if let Ok(matches) = matches {
|
||||||
let options = Options::from_matches(&matches)?;
|
let options = Options::from_matches(&matches)?;
|
||||||
|
|
||||||
if options.overwrite == OverwriteMode::NoClobber && options.backup != BackupMode::NoBackup {
|
if options.overwrite == OverwriteMode::NoClobber && options.backup != BackupMode::NoBackup {
|
||||||
|
@ -501,6 +512,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
};
|
};
|
||||||
set_exit_code(EXIT_ERR);
|
set_exit_code(EXIT_ERR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
if let Ok(matches) = command.try_get_matches_from_mut(args) {
|
if let Ok(matches) = command.try_get_matches_from_mut(args) {
|
||||||
let error = if matches.index_of("help").is_some() {
|
let error = if matches.index_of("help").is_some() {
|
||||||
command.print_long_help()
|
command.print_help()
|
||||||
} else if matches.index_of("version").is_some() {
|
} else if matches.index_of("version").is_some() {
|
||||||
writeln!(std::io::stdout(), "{}", command.render_version())
|
writeln!(std::io::stdout(), "{}", command.render_version())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -399,7 +399,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present(options::HELP) {
|
if matches.is_present(options::HELP) {
|
||||||
command.print_long_help()?;
|
command.print_help()?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1272,6 +1272,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Command::new(uucore::util_name())
|
Command::new(uucore::util_name())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
|
.after_help(LONG_HELP_KEYS)
|
||||||
.override_usage(format_usage(USAGE))
|
.override_usage(format_usage(USAGE))
|
||||||
.infer_long_args(true)
|
.infer_long_args(true)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -1421,7 +1422,6 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.short('k')
|
.short('k')
|
||||||
.long(options::KEY)
|
.long(options::KEY)
|
||||||
.help("sort by a key")
|
.help("sort by a key")
|
||||||
.long_help(LONG_HELP_KEYS)
|
|
||||||
.multiple_occurrences(true)
|
.multiple_occurrences(true)
|
||||||
.number_of_values(1)
|
.number_of_values(1)
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
|
@ -1466,8 +1466,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::COMPRESS_PROG)
|
Arg::new(options::COMPRESS_PROG)
|
||||||
.long(options::COMPRESS_PROG)
|
.long(options::COMPRESS_PROG)
|
||||||
.help("compress temporary files with PROG, decompress with PROG -d")
|
.help("compress temporary files with PROG, decompress with PROG -d; PROG has to take input from stdin and output to stdout")
|
||||||
.long_help("PROG has to take input from stdin and output to stdout")
|
|
||||||
.value_name("PROG"),
|
.value_name("PROG"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
if let Ok(matches) = command.try_get_matches_from_mut(args) {
|
if let Ok(matches) = command.try_get_matches_from_mut(args) {
|
||||||
let error = if matches.index_of("help").is_some() {
|
let error = if matches.index_of("help").is_some() {
|
||||||
command.print_long_help()
|
command.print_help()
|
||||||
} else if matches.index_of("version").is_some() {
|
} else if matches.index_of("version").is_some() {
|
||||||
writeln!(std::io::stdout(), "{}", command.render_version())
|
writeln!(std::io::stdout(), "{}", command.render_version())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::TABS)
|
Arg::new(options::TABS)
|
||||||
.short('t')
|
.short('t')
|
||||||
.long(options::TABS)
|
.long(options::TABS)
|
||||||
.long_help("use comma separated LIST of tab positions or have tabs N characters apart instead of 8 (enables -a)")
|
.help("use comma separated LIST of tab positions or have tabs N characters apart instead of 8 (enables -a)")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
|
@ -183,8 +183,6 @@ sed -i -e "s~ sed -n \"1s/'\\\/'/'OPT'/p\" < err >> pat || framework_failure_~
|
||||||
sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|runcon) return;; esac/" -e "s/rcexp=125 ;;/rcexp=2 ;;\ncp|truncate|pr) rcexp=1;;/" tests/misc/usage_vs_getopt.sh
|
sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|runcon) return;; esac/" -e "s/rcexp=125 ;;/rcexp=2 ;;\ncp|truncate|pr) rcexp=1;;/" tests/misc/usage_vs_getopt.sh
|
||||||
# GNU has option=[SUFFIX], clap is <SUFFIX>
|
# GNU has option=[SUFFIX], clap is <SUFFIX>
|
||||||
sed -i -e "s/cat opts/sed -i -e \"s| <.\*>$||g\" opts/" tests/misc/usage_vs_getopt.sh
|
sed -i -e "s/cat opts/sed -i -e \"s| <.\*>$||g\" opts/" tests/misc/usage_vs_getopt.sh
|
||||||
# Strip empty lines for the diff - see https://github.com/uutils/coreutils/issues/3370
|
|
||||||
sed -i -e "s~out 2>err1~out 2>err1\nsed '/^$/d' out > out\nsed '/^$/d' help > help~" tests/misc/usage_vs_getopt.sh
|
|
||||||
# for some reasons, some stuff are duplicated, strip that
|
# for some reasons, some stuff are duplicated, strip that
|
||||||
sed -i -e "s/provoked error./provoked error\ncat pat |sort -u > pat/" tests/misc/usage_vs_getopt.sh
|
sed -i -e "s/provoked error./provoked error\ncat pat |sort -u > pat/" tests/misc/usage_vs_getopt.sh
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue