This commit is contained in:
2024-05-21 18:32:52 +02:00
commit 8c6ae8f237
6 changed files with 309 additions and 0 deletions

8
src/arguments.rs Normal file
View File

@@ -0,0 +1,8 @@
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Arguments {
#[arg(short, long, help = "The menu prompt message", default_value_t = String::from(""))]
pub prompt: String,
}

34
src/executables.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::{error::Error, fs, path::Path};
pub fn get_executables() -> Result<Vec<String>, Box<dyn Error>> {
let mut executables: Vec<String> = Vec::new();
get_files(Path::new("/usr/local"), &mut executables)?;
get_files(Path::new("/bin"), &mut executables)?;
Ok(executables)
}
pub fn get_files(path: &Path, files: &mut Vec<String>) -> Result<(), Box<dyn Error>> {
let dirs = fs::read_dir(path)?;
for e in dirs {
let entry = e.unwrap();
let file_type = entry.file_type()?;
if file_type.is_dir() {
get_files(&entry.path(), files)?;
continue;
}
match entry.file_name().into_string() {
Ok(file_name) => {
if !files.contains(&file_name) {
files.push(file_name)
}
}
Err(_) => {}
}
}
Ok(())
}

19
src/main.rs Normal file
View File

@@ -0,0 +1,19 @@
use std::{error::Error, process::{self, Stdio}};
use clap::Parser;
use executables::get_executables;
mod arguments;
mod executables;
fn main() -> Result<(), Box<dyn Error>> {
let args = arguments::Arguments::parse();
let executables = get_executables()?;
Ok(())
}
fn run(program: impl ToString) {
let _ = process::Command::new(program.to_string()).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()).spawn();
}