Skip to content

Commit 2cb9b88

Browse files
authored
env: fix --version and protect against argv[0] (#11370)
1 parent c6b8a81 commit 2cb9b88

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/uu/env/src/env.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod string_parser;
1212
pub mod variable_parser;
1313

1414
use clap::builder::ValueParser;
15-
use clap::{Arg, ArgAction, Command, crate_name};
15+
use clap::{Arg, ArgAction, Command};
1616
use ini::Ini;
1717
use native_int_str::{
1818
Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, from_native_int_representation_owned,
@@ -338,9 +338,9 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
338338
}
339339

340340
pub fn uu_app() -> Command {
341-
Command::new(crate_name!())
341+
Command::new("env")
342342
.version(uucore::crate_version!())
343-
.help_template(uucore::localized_help_template(uucore::util_name()))
343+
.help_template(uucore::localized_help_template("env"))
344344
.about(translate!("env-about"))
345345
.override_usage(format_usage(&translate!("env-usage")))
346346
.after_help(translate!("env-after-help"))
@@ -657,12 +657,11 @@ impl EnvAppData {
657657
| clap::error::ErrorKind::DisplayVersion => return Err(e.into()),
658658
_ => {
659659
// Use ErrorFormatter directly to handle error with shebang message callback
660-
let formatter =
661-
uucore::clap_localization::ErrorFormatter::new(uucore::util_name());
660+
let formatter = uucore::clap_localization::ErrorFormatter::new("env");
662661
formatter.print_error_and_exit_with_callback(&e, 125, || {
663-
eprintln!(
664-
"{}: {}",
665-
uucore::util_name(),
662+
let _ = writeln!(
663+
stderr(),
664+
"env: {}",
666665
translate!("env-error-use-s-shebang")
667666
);
668667
});

tests/by-util/test_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn test_env_version() {
140140
.arg("--version")
141141
.succeeds()
142142
.no_stderr()
143-
.stdout_contains(util_name!());
143+
.stdout_is(format!("env {}\n", uucore::crate_version!()));
144144
}
145145

146146
#[test]

0 commit comments

Comments
 (0)