mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-13 15:00:15 +01:00
refactor: reuse executable list
This commit is contained in:
parent
0ab8f269a1
commit
f47bf23f6a
7 changed files with 35 additions and 42 deletions
18
src/shell.rs
18
src/shell.rs
|
|
@ -7,6 +7,8 @@ use std::time::Duration;
|
|||
|
||||
use regex_lite::Regex;
|
||||
|
||||
use crate::files::get_path_files;
|
||||
|
||||
pub const PRIVILEGE_LIST: [&str; 2] = ["sudo", "doas"];
|
||||
|
||||
pub enum Mode {
|
||||
|
|
@ -23,6 +25,7 @@ pub struct Data {
|
|||
pub alias: Option<HashMap<String, String>>,
|
||||
pub privilege: Option<String>,
|
||||
pub error: String,
|
||||
pub executables: Vec<String>,
|
||||
pub mode: Mode,
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +52,7 @@ impl Data {
|
|||
split: vec![],
|
||||
privilege: None,
|
||||
error: "".to_string(),
|
||||
executables: vec![],
|
||||
mode,
|
||||
};
|
||||
|
||||
|
|
@ -119,6 +123,20 @@ impl Data {
|
|||
self.candidates.push(candidate.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_executables(&mut self) -> &Vec<String> {
|
||||
if self.executables.is_empty() {
|
||||
self.executables = get_path_files();
|
||||
}
|
||||
&self.executables
|
||||
}
|
||||
|
||||
pub fn has_executable(&mut self, executable: &str) -> bool {
|
||||
if self.executables.is_empty() {
|
||||
self.executables = get_path_files();
|
||||
}
|
||||
self.executables.contains(&executable.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn split_command(command: &str) -> Vec<String> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue