Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/src/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ ls -w=80
```

With GNU coreutils, `--help` usually prints the help message and `--version` prints the version.
We also commonly provide short options: `-h` for help and `-V` for version.
We also have short aliases for them: `-h` for help and `-V` for version for few utils. But we deprecate them since it cause confusion at some cases e.g. `sort -h`.

## `coreutils`

Expand Down
6 changes: 3 additions & 3 deletions src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn main() {
match util {
"--list" => {
// If --help is also present, show usage instead of list
if args.any(|arg| arg == "--help" || arg == "-h") {
if args.any(|arg| arg == "--help") {
usage(&utils, binary_as_util);
process::exit(0);
}
Expand All @@ -87,7 +87,7 @@ fn main() {
}
process::exit(0);
}
"--version" | "-V" => {
"--version" => {
println!("{binary_as_util} {VERSION} (multi-call binary)");
process::exit(0);
}
Expand All @@ -106,7 +106,7 @@ fn main() {
process::exit(uumain(vec![util_os].into_iter().chain(args)));
}
None => {
if util == "--help" || util == "-h" {
if util == "--help" {
// see if they want help on a specific util
if let Some(util_os) = args.next() {
let Some(util) = util_os.to_str() else {
Expand Down
29 changes: 14 additions & 15 deletions tests/test_util_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,20 @@ fn util_version() {
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
return;
}
for arg in ["-V", "--version"] {
let child = Command::new(&scenario.bin_path)
.arg(arg)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
let ver = env::var("CARGO_PKG_VERSION").unwrap();
assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str);
}

let child = Command::new(&scenario.bin_path)
.arg("--version")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
let ver = env::var("CARGO_PKG_VERSION").unwrap();
assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str);
}

#[test]
Expand Down
Loading