+
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
12 changes: 10 additions & 2 deletions src/xargs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
process::{Command, Stdio},
};

use clap::{crate_version, Arg, ArgAction};
use clap::{crate_version, error::ErrorKind, Arg, ArgAction};

mod options {
pub const COMMAND: &str = "COMMAND";
Expand Down Expand Up @@ -954,7 +954,15 @@ fn do_xargs(args: &[&str]) -> Result<CommandResult, XargsError> {

let matches = match matches {
Ok(m) => m,
Err(e) => return Err(XargsError::from(e.to_string())),
Err(e) => match e.kind() {
ErrorKind::DisplayHelp | ErrorKind::DisplayVersion => {
// The help/version text already has a newline, so use `print!` here, not `println!`
print!("{e}");

return Ok(CommandResult::Success);
}
_ => return Err(XargsError::from(e.to_string())),
},
};

let options = Options {
Expand Down
32 changes: 32 additions & 0 deletions tests/xargs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,35 @@ fn xargs_replace_multiple_lines() {
.stderr(predicate::str::is_empty())
.stdout(predicate::str::diff("\n\n\n"));
}

#[test]
fn xargs_help() {
for option_style in ["-h", "--help"] {
Command::cargo_bin("xargs")
.expect("found binary")
.args([option_style])
.assert()
.success()
.stderr(predicate::str::is_empty())
.stdout(predicate::str::contains("--help"));
}
}

// Do not regress to:
//
// ❯ xargs --version
// Error: xargs 0.7.0
//
// Same for help above
#[test]
fn xargs_version() {
for option_style in ["-V", "--version"] {
Command::cargo_bin("xargs")
.expect("found binary")
.args([option_style])
.assert()
.success()
.stderr(predicate::str::is_empty())
.stdout(predicate::str::starts_with("xargs "));
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载