echo: show version when using --version

This commit is contained in:
Daniel Hofstetter 2025-07-14 12:31:32 +02:00
parent afbe90feaf
commit 9c08dd9851
2 changed files with 12 additions and 0 deletions

View file

@ -167,6 +167,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// echo --help
uu_app().print_help()?;
return Ok(());
} else if args.len() == 1 && args[0] == "--version" {
print!("{}", uu_app().render_version());
return Ok(());
} else {
// if POSIXLY_CORRECT is not set we filter the flags normally
filter_flags(args.into_iter())

View file

@ -4,6 +4,7 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) araba merci efjkow
use regex::Regex;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util::UCommand;
@ -514,6 +515,14 @@ fn partial_help_argument() {
new_ucmd!().arg("--he").succeeds().stdout_is("--he\n");
}
#[test]
fn full_version_argument() {
new_ucmd!()
.arg("--version")
.succeeds()
.stdout_matches(&Regex::new(r"^echo \(uutils coreutils\) (\d+\.\d+\.\d+)\n$").unwrap());
}
#[test]
fn only_help_argument_prints_help() {
assert_ne!(new_ucmd!().arg("--help").succeeds().stdout(), b"--help\n");