File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ pub enum SudoAction {
23
23
Version ( SudoVersionOptions ) ,
24
24
}
25
25
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
+
26
33
impl SudoAction {
27
34
/// try to parse and environment variable assignment
28
35
/// parse command line arguments from the environment and handle errors
@@ -631,11 +638,7 @@ impl SudoOptions {
631
638
{
632
639
let mut arg_iter = iter. into_iter ( ) . map ( Into :: into) ;
633
640
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 ( ) ) ;
639
642
640
643
let mut options = Self {
641
644
edit : invoked_as_sudoedit,
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ fn sudo_process() -> Result<(), Error> {
68
68
69
69
let usage_msg: & str ;
70
70
let long_help: fn ( ) -> String ;
71
- if std:: env:: args ( ) . next ( ) . as_deref ( ) == Some ( "sudoedit" ) {
71
+ if cli :: is_sudoedit ( std:: env:: args ( ) . next ( ) ) {
72
72
usage_msg = cli:: help_edit:: USAGE_MSG ;
73
73
long_help = cli:: help_edit:: long_help_message;
74
74
} else {
You can’t perform that action at this time.
0 commit comments