Skip to content

Commit 07ece8e

Browse files
committed
use the same check for sudoedit
1 parent 3e5409a commit 07ece8e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/sudo/cli/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ pub enum SudoAction {
2323
Version(SudoVersionOptions),
2424
}
2525

26+
pub(super) fn is_sudoedit(command_path: Option<String>) -> bool {
27+
use std::os::unix::ffi::OsStrExt;
28+
std::path::Path::new(&command_path.unwrap_or_default())
29+
.file_name()
30+
.is_some_and(|name| name.as_bytes().starts_with(b"sudoedit"))
31+
}
32+
2633
impl SudoAction {
2734
/// try to parse and environment variable assignment
2835
/// parse command line arguments from the environment and handle errors
@@ -631,11 +638,7 @@ impl SudoOptions {
631638
{
632639
let mut arg_iter = iter.into_iter().map(Into::into);
633640

634-
use std::os::unix::ffi::OsStrExt;
635-
636-
let invoked_as_sudoedit = std::path::Path::new(&arg_iter.next().unwrap_or_default())
637-
.file_name()
638-
.is_some_and(|name| name.as_bytes().starts_with(b"sudoedit"));
641+
let invoked_as_sudoedit = is_sudoedit(arg_iter.next());
639642

640643
let mut options = Self {
641644
edit: invoked_as_sudoedit,

src/sudo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn sudo_process() -> Result<(), Error> {
6868

6969
let usage_msg: &str;
7070
let long_help: fn() -> String;
71-
if std::env::args().next().as_deref() == Some("sudoedit") {
71+
if cli::is_sudoedit(std::env::args().next()) {
7272
usage_msg = cli::help_edit::USAGE_MSG;
7373
long_help = cli::help_edit::long_help_message;
7474
} else {

0 commit comments

Comments
 (0)