| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}; |
| 2 | |
| 3 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#; |
| 4 | |
| 5 | use superrust-analyzer cargo sudo-rs 0.2.14 su/::DEFAULT_USERrust-analyzer cargo sudo-rs 0.2.14 su/DEFAULT_USER.; |
| 6 | |
| 7 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 8 | pub enum SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction# { |
| 9 | Helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Help#(SuHelpOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuHelpOptions#), |
| 10 | Versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Version#(SuVersionOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuVersionOptions#), |
| 11 | Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#), |
| 12 | } |
| 13 | |
| 14 | impl SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction# { |
| 15 | pub fn from_envrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuAction]from_env().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuAction], Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 16 | SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..validaterust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]validate().() |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 21 | pub struct SuHelpOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuHelpOptions# {} |
| 22 | |
| 23 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#> for SuHelpOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuHelpOptions# { |
| 24 | type Errorrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuHelpOptions][`TryFrom<SuOptions>`]Error# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 25 | |
| 26 | fn try_fromrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuHelpOptions][`TryFrom<SuOptions>`]try_from().(mut opts: SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuHelpOptions][`TryFrom<SuOptions>`], Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuHelpOptions][`TryFrom<SuOptions>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 27 | let help = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help.); |
| 28 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(help); |
| 29 | reject_allrust-analyzer cargo sudo-rs 0.2.14 su/cli/reject_all().("--help", opts)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 30 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuHelpOptions][`TryFrom<SuOptions>`] {}) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | #[cfg_attr(test, derive(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 35 | pub struct SuVersionOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuVersionOptions# {} |
| 36 | |
| 37 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#> for SuVersionOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuVersionOptions# { |
| 38 | type Errorrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuVersionOptions][`TryFrom<SuOptions>`]Error# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 39 | |
| 40 | fn try_fromrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuVersionOptions][`TryFrom<SuOptions>`]try_from().(mut opts: SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuVersionOptions][`TryFrom<SuOptions>`], Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuVersionOptions][`TryFrom<SuOptions>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 41 | let version = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version.); |
| 42 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(version); |
| 43 | reject_allrust-analyzer cargo sudo-rs 0.2.14 su/cli/reject_all().("--version", opts)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 44 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuVersionOptions][`TryFrom<SuOptions>`] {}) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 49 | #[cfg_attr(test, derive(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:))] |
| 50 | pub struct SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 51 | // -c |
| 52 | pub commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>, |
| 53 | // -g |
| 54 | pub grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#>, |
| 55 | // -l |
| 56 | pub loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: bool, |
| 57 | // -p |
| 58 | pub preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#preserve_environment.: bool, |
| 59 | // -s |
| 60 | pub shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, |
| 61 | // -G |
| 62 | pub supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#supp_group.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#>, |
| 63 | // -w |
| 64 | pub whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#whitelist_environment.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 65 | |
| 66 | pub userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#, |
| 67 | pub argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>, |
| 68 | } |
| 69 | |
| 70 | #[cfg(test)] |
| 71 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 72 | fn defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() -> Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default] { |
| 73 | Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default] { |
| 74 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 75 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 76 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: false, |
| 77 | preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#preserve_environment.: false, |
| 78 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 79 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#supp_group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 80 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#whitelist_environment.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 81 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: DEFAULT_USERrust-analyzer cargo sudo-rs 0.2.14 su/DEFAULT_USER..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 82 | argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#> for SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 88 | type Errorrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][`TryFrom<SuOptions>`]Error# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 89 | |
| 90 | fn try_fromrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][`TryFrom<SuOptions>`]try_from().(mut opts: SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][`TryFrom<SuOptions>`], Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][`TryFrom<SuOptions>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> { |
| 91 | let command = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#command.); |
| 92 | let group = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#group.); |
| 93 | let login = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login.); |
| 94 | let preserve_environment = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment.); |
| 95 | // always `true`; cannot be disabled via the CLI |
| 96 | let _pty = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#pty.); |
| 97 | let shell = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#shell.); |
| 98 | let supp_group = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#supp_group.); |
| 99 | let whitelist_environment = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#whitelist_environment.); |
| 100 | let mut positional_args = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut opts.positional_argsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#positional_args.); |
| 101 | |
| 102 | reject_allrust-analyzer cargo sudo-rs 0.2.14 su/cli/reject_all().("run mode", opts)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | |
| 104 | let user = if positional_args.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 105 | DEFAULT_USERrust-analyzer cargo sudo-rs 0.2.14 su/DEFAULT_USER..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 106 | } else { |
| 107 | positional_args.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(0) |
| 108 | }; |
| 109 | let arguments = positional_args.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<String>`]from().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 110 | |
| 111 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][`TryFrom<SuOptions>`] { |
| 112 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command., |
| 113 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group., |
| 114 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login., |
| 115 | preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#preserve_environment., |
| 116 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell., |
| 117 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#supp_group., |
| 118 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#whitelist_environment., |
| 119 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#::try_fromrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][`TryFrom<String>`]try_from().(user).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 120 | argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments., |
| 121 | }) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | fn reject_allrust-analyzer cargo sudo-rs 0.2.14 su/cli/reject_all().(context: &str, opts: SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 126 | macro_rules! ensure_options_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/ensure_options_absent! { |
| 127 | ($($opt:ident,)*) => { |
| 128 | let SuOptions { |
| 129 | $($opt),* |
| 130 | } = opts; |
| 131 | |
| 132 | $(if !$opt.is_absent() { |
| 133 | let name = concat!("--", stringify!($opt)).replace('_', "-"); |
| 134 | return Err(format!("{context} conflicts with {name}")); |
| 135 | })* |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | ensure_options_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/ensure_options_absent!! { |
| 140 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#command., |
| 141 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#group., |
| 142 | helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help., |
| 143 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login., |
| 144 | preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment., |
| 145 | ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#pty., |
| 146 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#shell., |
| 147 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#supp_group., |
| 148 | versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version., |
| 149 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#whitelist_environment., |
| 150 | positional_argsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#positional_args., |
| 151 | }; |
| 152 | |
| 153 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().positional_args.is_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[`Vec<T>`][IsAbsent]is_absent().() { |
| 154 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{context} conflicts with positional argument")); |
| 155 | } |
| 156 | |
| 157 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 158 | } |
| 159 | |
| 160 | trait IsAbsentrust-analyzer cargo sudo-rs 0.2.14 su/cli/IsAbsent# { |
| 161 | fn is_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/IsAbsent#is_absent().(&self) -> bool; |
| 162 | } |
| 163 | |
| 164 | impl IsAbsentrust-analyzer cargo sudo-rs 0.2.14 su/cli/IsAbsent# for bool { |
| 165 | fn is_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[bool][IsAbsent]is_absent().(&self) -> bool { |
| 166 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | impl<T> IsAbsentrust-analyzer cargo sudo-rs 0.2.14 su/cli/IsAbsent# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 171 | fn is_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[`Option<T>`][IsAbsent]is_absent().(&self) -> bool { |
| 172 | self.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | impl<T> IsAbsentrust-analyzer cargo sudo-rs 0.2.14 su/cli/IsAbsent# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T> { |
| 177 | fn is_absentrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[`Vec<T>`][IsAbsent]is_absent().(&self) -> bool { |
| 178 | self.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 183 | pub(superrust-analyzer cargo sudo-rs 0.2.14 su/) struct SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions# { |
| 184 | // -c |
| 185 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#command.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>, |
| 186 | // -g |
| 187 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#group.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#>, |
| 188 | // -h |
| 189 | helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help.: bool, |
| 190 | // -l |
| 191 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login.: bool, |
| 192 | // -p |
| 193 | preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment.: bool, |
| 194 | // -P |
| 195 | ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#pty.: bool, |
| 196 | // -s |
| 197 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#shell.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, |
| 198 | // -G |
| 199 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#supp_group.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#>, |
| 200 | // -V |
| 201 | versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version.: bool, |
| 202 | // -w |
| 203 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#whitelist_environment.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 204 | |
| 205 | positional_argsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#positional_args.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 206 | } |
| 207 | |
| 208 | type OptionSetterrust-analyzer cargo sudo-rs 0.2.14 su/cli/OptionSetter# = fn(&mut SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>; |
| 209 | |
| 210 | struct SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 211 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: char, |
| 212 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: &'static str, |
| 213 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: bool, |
| 214 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: OptionSetterrust-analyzer cargo sudo-rs 0.2.14 su/cli/OptionSetter#, |
| 215 | } |
| 216 | |
| 217 | impl SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions# { |
| 218 | const SU_OPTIONSrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]SU_OPTIONS.: &'static [SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#] = &[ |
| 219 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 220 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'c', |
| 221 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "command", |
| 222 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: true, |
| 223 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, argument| { |
| 224 | if argument.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 225 | sudo_options.commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#command. = argument.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<String>`]from().); |
| 226 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 227 | } else { |
| 228 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no command provided".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 229 | } |
| 230 | }, |
| 231 | }, |
| 232 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 233 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'g', |
| 234 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "group", |
| 235 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: true, |
| 236 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, argument| { |
| 237 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = argument { |
| 238 | sudo_options.grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#group..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#::from_cli_stringrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]from_cli_string().(value)); |
| 239 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 240 | } else { |
| 241 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no group provided".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 242 | } |
| 243 | }, |
| 244 | }, |
| 245 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 246 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'G', |
| 247 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "supp-group", |
| 248 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: true, |
| 249 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, argument| { |
| 250 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = argument { |
| 251 | sudo_options |
| 252 | .supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#supp_group. |
| 253 | .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#::from_cli_stringrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]from_cli_string().(value)); |
| 254 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 255 | } else { |
| 256 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no supplementary group provided".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 257 | } |
| 258 | }, |
| 259 | }, |
| 260 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 261 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'l', |
| 262 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "login", |
| 263 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 264 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 265 | if sudo_options.loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login. { |
| 266 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--login")) |
| 267 | } else { |
| 268 | sudo_options.loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login. = true; |
| 269 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 270 | } |
| 271 | }, |
| 272 | }, |
| 273 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 274 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'p', |
| 275 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "preserve-environment", |
| 276 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 277 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 278 | if sudo_options.preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment. { |
| 279 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--preserve-environment")) |
| 280 | } else { |
| 281 | sudo_options.preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment. = true; |
| 282 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 283 | } |
| 284 | }, |
| 285 | }, |
| 286 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 287 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'm', |
| 288 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "preserve-environment", |
| 289 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 290 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 291 | if sudo_options.preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment. { |
| 292 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--preserve-environment")) |
| 293 | } else { |
| 294 | sudo_options.preserve_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#preserve_environment. = true; |
| 295 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 296 | } |
| 297 | }, |
| 298 | }, |
| 299 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 300 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'P', |
| 301 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "pty", |
| 302 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 303 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 304 | if sudo_options.ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#pty. { |
| 305 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--pty")) |
| 306 | } else { |
| 307 | sudo_options.ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#pty. = true; |
| 308 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 309 | } |
| 310 | }, |
| 311 | }, |
| 312 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 313 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 's', |
| 314 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "shell", |
| 315 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: true, |
| 316 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, argument| { |
| 317 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = argument { |
| 318 | sudo_options.shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#shell. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<String>`]from().(path)); |
| 319 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 320 | } else { |
| 321 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no shell provided".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 322 | } |
| 323 | }, |
| 324 | }, |
| 325 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 326 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'w', |
| 327 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "whitelist-environment", |
| 328 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: true, |
| 329 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, argument| { |
| 330 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(list) = argument { |
| 331 | let values: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = list.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(str::to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 332 | sudo_options.whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#whitelist_environment..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(values); |
| 333 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 334 | } else { |
| 335 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("no environment whitelist provided".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 336 | } |
| 337 | }, |
| 338 | }, |
| 339 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 340 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'V', |
| 341 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "version", |
| 342 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 343 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 344 | if sudo_options.versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version. { |
| 345 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--version")) |
| 346 | } else { |
| 347 | sudo_options.versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version. = true; |
| 348 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 349 | } |
| 350 | }, |
| 351 | }, |
| 352 | SuOptionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption# { |
| 353 | shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short.: 'h', |
| 354 | longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.: "help", |
| 355 | takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument.: false, |
| 356 | setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.: |sudo_options, _| { |
| 357 | if sudo_options.helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help. { |
| 358 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--help")) |
| 359 | } else { |
| 360 | sudo_options.helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help. = true; |
| 361 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 362 | } |
| 363 | }, |
| 364 | }, |
| 365 | ]; |
| 366 | |
| 367 | /// parse su arguments into SuOptions struct |
| 368 | pub(superrust-analyzer cargo sudo-rs 0.2.14 su/) fn parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().( |
| 369 | arguments: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 370 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 371 | let mut options: SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions# = SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions][Default]default().(); |
| 372 | let mut arg_iter = arguments.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1); |
| 373 | |
| 374 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(arg) = arg_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().() { |
| 375 | // - or -l or --login indicates a login shell should be started |
| 376 | if arg rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."-" { |
| 377 | if options.loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login. { |
| 378 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().("--login")); |
| 379 | } else { |
| 380 | options.loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#login. = true; |
| 381 | } |
| 382 | } else if arg rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."--" { |
| 383 | // only positional arguments after this point |
| 384 | options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#positional_args..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(arg_iter); |
| 385 | |
| 386 | break; |
| 387 | |
| 388 | // if the argument starts with -- it must be a full length option name |
| 389 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unprefixed) = arg.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("--") { |
| 390 | // parse assignments like '--group=ferris' |
| 391 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((key, value)) = unprefixed.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('=') { |
| 392 | // lookup the option by name |
| 393 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(option) = Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]::SU_OPTIONSrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]SU_OPTIONS..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|o| o.longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().key) { |
| 394 | // the value is already present, when the option does not take any arguments this results in an error |
| 395 | if option.takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument. { |
| 396 | (option.setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.)(&mut options, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 397 | } else { |
| 398 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("'--{}' does not take any arguments", option.longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 399 | } |
| 400 | } else { |
| 401 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unrecognized option '{arg}'"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 402 | } |
| 403 | // lookup the option |
| 404 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(option) = Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]::SU_OPTIONSrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]SU_OPTIONS..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|o| o.longrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#long. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().unprefixed) |
| 405 | { |
| 406 | // try to parse an argument when the option needs an argument |
| 407 | if option.takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument. { |
| 408 | let next_arg = arg_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().(); |
| 409 | (option.setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.)(&mut options, next_arg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 410 | } else { |
| 411 | (option.setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.)(&mut options, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 412 | } |
| 413 | } else { |
| 414 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unrecognized option '{arg}'"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 415 | } |
| 416 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unprefixed) = arg.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('-') { |
| 417 | // flags can be grouped, so we loop over the the characters |
| 418 | let mut chars = unprefixed.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().(); |
| 419 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(curr) = chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 420 | // lookup the option |
| 421 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(option) = Selfrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]::SU_OPTIONSrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]SU_OPTIONS..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|o| o.shortrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#short. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().curr) { |
| 422 | // try to parse an argument when one is necessary, either the rest of the current flag group or the next argument |
| 423 | let rest = chars.as_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`]as_str().(); |
| 424 | |
| 425 | if option.takes_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#takes_argument. { |
| 426 | let next_arg = if rest.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 427 | arg_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().() |
| 428 | } else { |
| 429 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rest.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 430 | }; |
| 431 | (option.setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.)(&mut options, next_arg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 432 | // stop looping over flags if the current flag takes an argument |
| 433 | break; |
| 434 | } else { |
| 435 | // parse flag without argument |
| 436 | (option.setrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOption#set.)(&mut options, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 437 | } |
| 438 | } else { |
| 439 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unrecognized option '{curr}'"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 440 | } |
| 441 | } |
| 442 | } else { |
| 443 | options.positional_argsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#positional_args..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(arg); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(options) |
| 448 | } |
| 449 | |
| 450 | pub(superrust-analyzer cargo sudo-rs 0.2.14 su/) fn validaterust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]validate().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 451 | let action = if self.helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#help. { |
| 452 | SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Help#(self.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 453 | } else if self.versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#version. { |
| 454 | SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Version#(self.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 455 | } else { |
| 456 | SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(self.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 457 | }; |
| 458 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(action) |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | fn more_than_oncerust-analyzer cargo sudo-rs 0.2.14 su/cli/more_than_once().(flag: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 463 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("argument '{flag}' was provided more than once, but cannot be used multiple times") |
| 464 | } |
| 465 | |
| 466 | #[cfg(test)] |
| 467 | mod testsrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/ { |
| 468 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/; |
| 469 | |
| 470 | use superrust-analyzer cargo sudo-rs 0.2.14 su/cli/::{SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#, SuHelpOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuHelpOptions#, SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#, SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#, SuVersionOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuVersionOptions#}; |
| 471 | |
| 472 | fn parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(args: &[&str]) -> SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction# { |
| 473 | let mut args = args.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>(); |
| 474 | args.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(0, "/bin/su".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 475 | SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(args) |
| 476 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 477 | .validaterust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]validate().() |
| 478 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 479 | } |
| 480 | |
| 481 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 482 | fn it_parses_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_group().() { |
| 483 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 484 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 485 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 486 | }); |
| 487 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-g", "ferris"])); |
| 488 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-gferris"])); |
| 489 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--group", "ferris"])); |
| 490 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--group=ferris"])); |
| 491 | } |
| 492 | |
| 493 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 494 | fn it_parses_shell_defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_shell_default().() { |
| 495 | let result = parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--shell", "/bin/bash"]); |
| 496 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 497 | result, |
| 498 | SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 499 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("/bin/bash".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 500 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 501 | }) |
| 502 | ); |
| 503 | } |
| 504 | |
| 505 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 506 | fn it_parses_whitelistrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_whitelist().() { |
| 507 | let result = parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-w", "FOO,BAR"]); |
| 508 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 509 | result, |
| 510 | SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 511 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#whitelist_environment.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "BAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 512 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 513 | }) |
| 514 | ); |
| 515 | } |
| 516 | |
| 517 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 518 | fn it_parses_combined_optionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_combined_options().() { |
| 519 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 520 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: true, |
| 521 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 522 | }); |
| 523 | |
| 524 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-Pl"])); |
| 525 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-lP"])); |
| 526 | } |
| 527 | |
| 528 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 529 | fn it_parses_combined_options_and_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_combined_options_and_arguments().() { |
| 530 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 531 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: true, |
| 532 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("/bin/bash".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 533 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 534 | }); |
| 535 | |
| 536 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-Pls/bin/bash"])); |
| 537 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-Pls", "/bin/bash"])); |
| 538 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-Pl", "-s/bin/bash"])); |
| 539 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-lP", "-s", "/bin/bash"])); |
| 540 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-lP", "--shell=/bin/bash"])); |
| 541 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-lP", "--shell", "/bin/bash"])); |
| 542 | } |
| 543 | |
| 544 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 545 | fn it_parses_an_userrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_an_user().() { |
| 546 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 547 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: "ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 548 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 549 | }); |
| 550 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-P", "ferris"])); |
| 551 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["ferris", "-P"])); |
| 552 | } |
| 553 | |
| 554 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 555 | fn it_parses_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_arguments().() { |
| 556 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 557 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: "ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 558 | argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["script.sh".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 559 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 560 | }); |
| 561 | |
| 562 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-P", "ferris", "script.sh"])); |
| 563 | } |
| 564 | |
| 565 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 566 | fn it_parses_commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_command().() { |
| 567 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 568 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("'echo hi'".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 569 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 570 | }); |
| 571 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-c", "'echo hi'"])); |
| 572 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-c'echo hi'"])); |
| 573 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--command", "'echo hi'"])); |
| 574 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--command='echo hi'"])); |
| 575 | |
| 576 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 577 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("env".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 578 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 579 | }); |
| 580 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-c", "env"])); |
| 581 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-cenv"])); |
| 582 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--command", "env"])); |
| 583 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--command=env"])); |
| 584 | } |
| 585 | |
| 586 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 587 | fn it_parses_supplementary_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_supplementary_group().() { |
| 588 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 589 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#supp_group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 590 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 591 | }); |
| 592 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-G", "ferris"])); |
| 593 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-Gferris"])); |
| 594 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--supp-group", "ferris"])); |
| 595 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--supp-group=ferris"])); |
| 596 | } |
| 597 | |
| 598 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 599 | fn it_parses_multiple_supplementary_groupsrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_multiple_supplementary_groups().() { |
| 600 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 601 | supp_grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#supp_group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "krabbetje".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "krabbe".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 602 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 603 | }); |
| 604 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 605 | expected, |
| 606 | parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-G", "ferris", "-G", "krabbetje", "--supp-group", "krabbe"]) |
| 607 | ); |
| 608 | } |
| 609 | |
| 610 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 611 | fn it_parses_loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_login().() { |
| 612 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 613 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: true, |
| 614 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 615 | }); |
| 616 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-"])); |
| 617 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-l"])); |
| 618 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--login"])); |
| 619 | } |
| 620 | |
| 621 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 622 | fn it_parses_ptyrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_pty().() { |
| 623 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().()); |
| 624 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-P"])); |
| 625 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--pty"])); |
| 626 | } |
| 627 | |
| 628 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 629 | fn it_parses_shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_shell().() { |
| 630 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 631 | shellrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#shell.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("some-shell".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 632 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 633 | }); |
| 634 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-s", "some-shell"])); |
| 635 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-ssome-shell"])); |
| 636 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--shell", "some-shell"])); |
| 637 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--shell=some-shell"])); |
| 638 | } |
| 639 | |
| 640 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 641 | fn it_parses_whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_whitelist_environment().() { |
| 642 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 643 | whitelist_environmentrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#whitelist_environment.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "BAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 644 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 645 | }); |
| 646 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-w", "FOO,BAR"])); |
| 647 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-wFOO,BAR"])); |
| 648 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--whitelist-environment", "FOO,BAR"])); |
| 649 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--whitelist-environment=FOO,BAR"])); |
| 650 | } |
| 651 | |
| 652 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 653 | fn it_parses_helprust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_help().() { |
| 654 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Helprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Help#(SuHelpOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuHelpOptions# {}); |
| 655 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-h"])); |
| 656 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--help"])); |
| 657 | } |
| 658 | |
| 659 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 660 | fn it_parses_versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/it_parses_version().() { |
| 661 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Versionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Version#(SuVersionOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuVersionOptions# {}); |
| 662 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-V"])); |
| 663 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--version"])); |
| 664 | } |
| 665 | |
| 666 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 667 | fn short_flag_whitespacerust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/short_flag_whitespace().() { |
| 668 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 669 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![" ".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 670 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 671 | }); |
| 672 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-g "])); |
| 673 | } |
| 674 | |
| 675 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 676 | fn short_flag_whitespace_positional_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/short_flag_whitespace_positional_argument().() { |
| 677 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 678 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![" ".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 679 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: "ghost".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 680 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 681 | }); |
| 682 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-g ", "ghost"])); |
| 683 | } |
| 684 | |
| 685 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 686 | fn long_flag_equal_whitespacerust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/long_flag_equal_whitespace().() { |
| 687 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 688 | grouprust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#group.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![" ".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 689 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 690 | }); |
| 691 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--group= "])); |
| 692 | } |
| 693 | |
| 694 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 695 | fn flag_after_positional_argumentrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/flag_after_positional_argument().() { |
| 696 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 697 | argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 698 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: true, |
| 699 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: "ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 700 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 701 | }); |
| 702 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["ferris", "-l"])); |
| 703 | } |
| 704 | |
| 705 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 706 | fn flags_after_dashrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/flags_after_dash().() { |
| 707 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 708 | commandrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#command.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("echo".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 709 | loginrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#login.: true, |
| 710 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 711 | }); |
| 712 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["-", "-c", "echo"])); |
| 713 | } |
| 714 | |
| 715 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 716 | fn only_positional_args_after_dashdashrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/only_positional_args_after_dashdash().() { |
| 717 | let expected = SuActionrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#::Runrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuAction#Run#(SuRunOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions# { |
| 718 | userrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#user.: "ferris".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 719 | argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuRunOptions#arguments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["-c".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "echo".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()], |
| 720 | ..<_>::defaultrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuRunOptions][Default]default().() |
| 721 | }); |
| 722 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, parserust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/parse().(&["--", "ferris", "-c", "echo"])); |
| 723 | } |
| 724 | |
| 725 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 726 | fn repeated_boolean_flagrust-analyzer cargo sudo-rs 0.2.14 su/cli/tests/repeated_boolean_flag().() { |
| 727 | let f = |s: &str| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 728 | |
| 729 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(["su", "-l", "-l"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(f)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 730 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(["su", "-", "-l"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(f)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 731 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(["su", "--login", "-l"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(f)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 732 | |
| 733 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(["su", "-p", "-p"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(f)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 734 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SuOptionsrust-analyzer cargo sudo-rs 0.2.14 su/cli/SuOptions#::parse_argumentsrust-analyzer cargo sudo-rs 0.2.14 su/cli/impl#[SuOptions]parse_arguments().(["su", "-p", "--preserve-environment"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(f)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 735 | } |
| 736 | } |