mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
stdbuf: clap 3
This commit is contained in:
parent
eaaa16291e
commit
0fca4460de
3 changed files with 18 additions and 18 deletions
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/stdbuf.rs"
|
path = "src/stdbuf.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
|
||||||
tempfile = "3.1"
|
tempfile = "3.1"
|
||||||
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
|
@ -40,11 +40,11 @@ static LONG_HELP: &str = "If MODE is 'L' the corresponding stream will be line b
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const INPUT: &str = "input";
|
pub const INPUT: &str = "input";
|
||||||
pub const INPUT_SHORT: &str = "i";
|
pub const INPUT_SHORT: char = 'i';
|
||||||
pub const OUTPUT: &str = "output";
|
pub const OUTPUT: &str = "output";
|
||||||
pub const OUTPUT_SHORT: &str = "o";
|
pub const OUTPUT_SHORT: char = 'o';
|
||||||
pub const ERROR: &str = "error";
|
pub const ERROR: &str = "error";
|
||||||
pub const ERROR_SHORT: &str = "e";
|
pub const ERROR_SHORT: char = 'e';
|
||||||
pub const COMMAND: &str = "command";
|
pub const COMMAND: &str = "command";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ struct ProgramOptions {
|
||||||
stderr: BufferType,
|
stderr: BufferType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<&ArgMatches<'a>> for ProgramOptions {
|
impl<'a> TryFrom<&ArgMatches> for ProgramOptions {
|
||||||
type Error = ProgramOptionsError;
|
type Error = ProgramOptionsError;
|
||||||
|
|
||||||
fn try_from(matches: &ArgMatches) -> Result<Self, Self::Error> {
|
fn try_from(matches: &ArgMatches) -> Result<Self, Self::Error> {
|
||||||
|
@ -156,7 +156,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
.accept_any();
|
.accept_any();
|
||||||
let usage = usage();
|
let usage = usage();
|
||||||
|
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
let matches = uu_app().override_usage(&usage[..]).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))?;
|
||||||
|
|
||||||
|
@ -191,41 +191,41 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
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)
|
||||||
.after_help(LONG_HELP)
|
.after_help(LONG_HELP)
|
||||||
.setting(AppSettings::TrailingVarArg)
|
.setting(AppSettings::TrailingVarArg)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::INPUT)
|
Arg::new(options::INPUT)
|
||||||
.long(options::INPUT)
|
.long(options::INPUT)
|
||||||
.short(options::INPUT_SHORT)
|
.short(options::INPUT_SHORT)
|
||||||
.help("adjust standard input stream buffering")
|
.help("adjust standard input stream buffering")
|
||||||
.value_name("MODE")
|
.value_name("MODE")
|
||||||
.required_unless_one(&[options::OUTPUT, options::ERROR]),
|
.required_unless_present_any(&[options::OUTPUT, options::ERROR]),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::OUTPUT)
|
Arg::new(options::OUTPUT)
|
||||||
.long(options::OUTPUT)
|
.long(options::OUTPUT)
|
||||||
.short(options::OUTPUT_SHORT)
|
.short(options::OUTPUT_SHORT)
|
||||||
.help("adjust standard output stream buffering")
|
.help("adjust standard output stream buffering")
|
||||||
.value_name("MODE")
|
.value_name("MODE")
|
||||||
.required_unless_one(&[options::INPUT, options::ERROR]),
|
.required_unless_present_any(&[options::INPUT, options::ERROR]),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::ERROR)
|
Arg::new(options::ERROR)
|
||||||
.long(options::ERROR)
|
.long(options::ERROR)
|
||||||
.short(options::ERROR_SHORT)
|
.short(options::ERROR_SHORT)
|
||||||
.help("adjust standard error stream buffering")
|
.help("adjust standard error stream buffering")
|
||||||
.value_name("MODE")
|
.value_name("MODE")
|
||||||
.required_unless_one(&[options::INPUT, options::OUTPUT]),
|
.required_unless_present_any(&[options::INPUT, options::OUTPUT]),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::COMMAND)
|
Arg::new(options::COMMAND)
|
||||||
.multiple(true)
|
.multiple_occurrences(true)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ fn test_stdbuf_no_buffer_option_fails() {
|
||||||
|
|
||||||
ts.ucmd().args(&["head"]).fails().stderr_is(&format!(
|
ts.ucmd().args(&["head"]).fails().stderr_is(&format!(
|
||||||
"error: The following required arguments were not provided:\n \
|
"error: The following required arguments were not provided:\n \
|
||||||
--error <MODE>\n \
|
|
||||||
--input <MODE>\n \
|
--input <MODE>\n \
|
||||||
--output <MODE>\n\n\
|
--output <MODE>\n \
|
||||||
|
--error <MODE>\n\n\
|
||||||
USAGE:\n \
|
USAGE:\n \
|
||||||
{1} {0} OPTION... COMMAND\n\n\
|
{1} {0} OPTION... COMMAND\n\n\
|
||||||
For more information try --help",
|
For more information try --help",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue