From 6699eaad6c5ceca771d7509a1a20ec651a3b0331 Mon Sep 17 00:00:00 2001 From: SSJDeathSpawn Date: Tue, 21 Mar 2023 18:19:17 +0530 Subject: [PATCH 1/2] Added condition to ensure name of utility appears --- src/uucore/src/lib/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 5cbf58faa..26beaff6e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -120,9 +120,17 @@ static ARGV: Lazy> = Lazy::new(|| wild::args_os().collect()); static UTIL_NAME: Lazy = Lazy::new(|| { if get_utility_is_second_arg() { - &ARGV[1] + let i = match ARGV[1].eq("manpage") { + true => 1, + false => 0, + }; + &ARGV[1 + i] } else { - &ARGV[0] + let i = match ARGV[0].eq("manpage") { + true => 1, + false => 0, + }; + &ARGV[i] } .to_string_lossy() .into_owned() From 4f88356035339b6e38c424fa30d875edeec0dadc Mon Sep 17 00:00:00 2001 From: SSJDeathSpawn Date: Tue, 21 Mar 2023 18:52:54 +0530 Subject: [PATCH 2/2] refactor: simplification and name change --- src/uucore/src/lib/lib.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 26beaff6e..9e7105b0e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -119,21 +119,11 @@ pub fn set_utility_is_second_arg() { static ARGV: Lazy> = Lazy::new(|| wild::args_os().collect()); static UTIL_NAME: Lazy = Lazy::new(|| { - if get_utility_is_second_arg() { - let i = match ARGV[1].eq("manpage") { - true => 1, - false => 0, - }; - &ARGV[1 + i] - } else { - let i = match ARGV[0].eq("manpage") { - true => 1, - false => 0, - }; - &ARGV[i] - } - .to_string_lossy() - .into_owned() + let base_index = if get_utility_is_second_arg() { 1 } else { 0 }; + let is_man = if ARGV[base_index].eq("manpage") { 1 } else { 0 }; + let argv_index = base_index + is_man; + + ARGV[argv_index].to_string_lossy().into_owned() }); /// Derive the utility name.