+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/xargs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ mod options {
pub const DELIMITER: &str = "delimiter";
pub const EXIT: &str = "exit";
pub const MAX_ARGS: &str = "max-args";
pub const MAX_CHARS: &str = "max-chars";
pub const MAX_LINES: &str = "max-lines";
pub const MAX_PROCS: &str = "max-procs";
pub const NO_RUN_IF_EMPTY: &str = "no-run-if-empty";
pub const NULL: &str = "null";
pub const SIZE: &str = "size";
pub const VERBOSE: &str = "verbose";
}

Expand All @@ -36,10 +36,10 @@ struct Options {
delimiter: Option<u8>,
exit_if_pass_char_limit: bool,
max_args: Option<usize>,
max_chars: Option<usize>,
max_lines: Option<usize>,
no_run_if_empty: bool,
null: bool,
size: Option<usize>,
verbose: bool,
}

Expand Down Expand Up @@ -803,9 +803,9 @@ fn do_xargs(args: &[&str]) -> Result<CommandResult, XargsError> {
.help("Split the input by null terminators rather than whitespace"),
)
.arg(
Arg::with_name(options::SIZE)
Arg::with_name(options::MAX_CHARS)
.short("s")
.long(options::SIZE)
.long(options::MAX_CHARS)
.takes_value(true)
.validator(validate_positive_usize)
.help(
Expand All @@ -832,14 +832,14 @@ fn do_xargs(args: &[&str]) -> Result<CommandResult, XargsError> {
max_args: matches
.value_of(options::MAX_ARGS)
.map(|value| value.parse().unwrap()),
max_chars: matches
.value_of(options::MAX_CHARS)
.map(|value| value.parse().unwrap()),
max_lines: matches
.value_of(options::MAX_LINES)
.map(|value| value.parse().unwrap()),
no_run_if_empty: matches.is_present(options::NO_RUN_IF_EMPTY),
null: matches.is_present(options::NULL),
size: matches
.value_of(options::SIZE)
.map(|value| value.parse().unwrap()),
verbose: matches.is_present(options::VERBOSE),
};

Expand Down Expand Up @@ -888,7 +888,7 @@ fn do_xargs(args: &[&str]) -> Result<CommandResult, XargsError> {
(None, None) => (),
}

if let Some(max_chars) = options.size {
if let Some(max_chars) = options.max_chars {
limiters.add(MaxCharsCommandSizeLimiter::new(max_chars));
}

Expand Down
18 changes: 10 additions & 8 deletions tests/xargs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ fn xargs_max_args_lines_conflict() {

#[test]
fn xargs_max_chars() {
Command::cargo_bin("xargs")
.expect("found binary")
.args(["-s11"])
.write_stdin("ab cd efg")
.assert()
.success()
.stderr(predicate::str::is_empty())
.stdout(predicate::str::diff("ab cd\nefg\n"));
for arg in ["-s11", "--max-chars=11"] {
Command::cargo_bin("xargs")
.expect("found binary")
.arg(arg)
.write_stdin("ab cd efg")
.assert()
.success()
.stderr(predicate::str::is_empty())
.stdout(predicate::str::diff("ab cd\nefg\n"));
}

// Behavior should be the same with -x, which only takes effect with -L or
// -n.
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载