Skip to content

Commit 723babf

Browse files
committed
true, false, echo: avoid uu_app().render_version() for smaller binary
1 parent ff6dd99 commit 723babf

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

src/uu/echo/src/echo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ffi::{OsStr, OsString};
1010
use std::io::{StdoutLock, Write, stdout};
1111
use uucore::error::UResult;
1212
use uucore::format::{FormatChar, OctalParsing, parse_escape_only};
13-
use uucore::{format_usage, os_str_as_bytes};
13+
use uucore::{crate_version, format_usage, os_str_as_bytes};
1414

1515
use uucore::translate;
1616

@@ -166,7 +166,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
166166
uu_app().print_help()?;
167167
return Ok(());
168168
} else if first_arg == "--version" && args.peek().is_none() {
169-
write!(stdout(), "{}", uu_app().render_version())?;
169+
writeln!(stdout(), "echo {}", crate_version!())?;
170170
return Ok(());
171171
}
172172

@@ -186,17 +186,17 @@ pub fn uu_app() -> Command {
186186
// Note: echo is different from the other utils in that it should **not**
187187
// have `infer_long_args(true)`, because, for example, `--ver` should be
188188
// printed as `--ver` and not show the version text.
189-
Command::new(uucore::util_name())
189+
Command::new("echo")
190190
// TrailingVarArg specifies the final positional argument is a VarArg
191191
// and it doesn't attempts the parse any further args.
192192
// Final argument must have multiple(true) or the usage string equivalent.
193193
.trailing_var_arg(true)
194194
.allow_hyphen_values(true)
195-
.version(uucore::crate_version!())
195+
.version(crate_version!())
196196
.about(translate!("echo-about"))
197197
.after_help(translate!("echo-after-help"))
198198
.override_usage(format_usage(&translate!("echo-usage")))
199-
.help_template(uucore::localized_help_template(uucore::util_name()))
199+
.help_template(uucore::localized_help_template("echo"))
200200
.arg(
201201
Arg::new(options::NO_NEWLINE)
202202
.short('n')

src/uu/false/src/false.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
use clap::{Arg, ArgAction, Command};
66
use std::io::Write;
7-
use uucore::translate;
7+
use uucore::{crate_version, translate};
88

99
// uucore::main does not support no-result
1010
pub fn uumain(mut args: impl uucore::Args) -> i32 {
@@ -16,23 +16,24 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 {
1616
let error = if flag == "--help" {
1717
uu_app().print_help()
1818
} else if flag == "--version" {
19-
write!(std::io::stdout(), "{}", uu_app().render_version())
19+
// avoid uu_app for smaller binary size
20+
writeln!(std::io::stdout(), "false {}", crate_version!())
2021
} else {
2122
return 1;
2223
};
2324

2425
if let Err(print_fail) = error
2526
&& print_fail.kind() != std::io::ErrorKind::BrokenPipe
2627
{
27-
let _ = writeln!(std::io::stderr(), "{}: {print_fail}", uucore::util_name());
28+
let _ = writeln!(std::io::stderr(), "false: {print_fail}");
2829
}
2930
1
3031
}
3132

3233
pub fn uu_app() -> Command {
33-
Command::new(uucore::util_name())
34-
.version(uucore::crate_version!())
35-
.help_template(uucore::localized_help_template(uucore::util_name()))
34+
Command::new("false")
35+
.version(crate_version!())
36+
.help_template(uucore::localized_help_template("false"))
3637
.about(translate!("false-about"))
3738
// We provide our own help and version options, to ensure maximum compatibility with GNU.
3839
.disable_help_flag(true)

src/uu/true/src/true.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
use clap::{Arg, ArgAction, Command};
66
use std::io::Write;
7-
use uucore::translate;
7+
use uucore::{crate_version, translate};
88

99
// uucore::main does not support no-result
1010
pub fn uumain(mut args: impl uucore::Args) -> i32 {
@@ -16,7 +16,8 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 {
1616
let error = if flag == "--help" {
1717
uu_app().print_help()
1818
} else if flag == "--version" {
19-
write!(std::io::stdout(), "{}", uu_app().render_version())
19+
// avoid uu_app for smaller binary size
20+
writeln!(std::io::stdout(), "true {}", crate_version!())
2021
} else {
2122
return 0;
2223
};
@@ -25,7 +26,7 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 {
2526
&& print_fail.kind() != std::io::ErrorKind::BrokenPipe
2627
{
2728
// Try to display this error.
28-
let _ = writeln!(std::io::stderr(), "{}: {print_fail}", uucore::util_name());
29+
let _ = writeln!(std::io::stderr(), "true: {print_fail}");
2930
// Mirror GNU options. When failing to print warnings or version flags, then we exit
3031
// with FAIL. This avoids allocation some error information which may result in yet
3132
// other types of failure.
@@ -35,9 +36,9 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 {
3536
}
3637

3738
pub fn uu_app() -> Command {
38-
Command::new(uucore::util_name())
39-
.version(uucore::crate_version!())
40-
.help_template(uucore::localized_help_template(uucore::util_name()))
39+
Command::new("true")
40+
.version(crate_version!())
41+
.help_template(uucore::localized_help_template("true"))
4142
.about(translate!("true-about"))
4243
// We provide our own help and version options, to ensure maximum compatibility with GNU.
4344
.disable_help_flag(true)

0 commit comments

Comments
 (0)