fixed the recursion problem

This commit is contained in:
2025-03-08 19:14:49 +05:30
parent 423321fe9f
commit 42f67d01ca

View File

@@ -13,7 +13,7 @@ struct Flatpak {
struct Asset;
fn main() -> io::Result<()> {
loop {
clear_terminal();
let binding = detect_distro();
@@ -31,24 +31,29 @@ fn main() -> io::Result<()> {
let first_choice: Vec<String> = buffer.lines().map(|line| line.to_string()).collect();
for(index, element) in first_choice.iter().enumerate() {
eprint!("{}. {}\n", index+1, element)
for (index, element) in first_choice.iter().enumerate() {
eprint!("{}. {}\n", index + 1, element);
}
eprint!("\nEnter 0 to exit\n");
let _ = match distro {
"arch" => arch_choices(),
"Debian" => debian_choices(),
"fedora" => fedora_choices(),
let input: i32 = handle_int_input();
if input == 0 {
break;
}
match distro {
"arch" => arch_choices(input)?, // Pass the input value here
"Debian" => debian_choices(input)?, // Pass the input value here
"fedora" => fedora_choices(input)?, // Pass the input value here
_ => return Err(io::Error::new(io::ErrorKind::NotFound, "Unsupported distro")),
};
}
Ok(())
}
fn arch_choices() -> io::Result<()> {
let input: i32 = handle_int_input();
fn arch_choices(input: i32) -> io::Result<()> {
let _ = match input {
1 => install_programs(),
@@ -62,9 +67,7 @@ fn arch_choices() -> io::Result<()> {
Ok(())
}
fn debian_choices() -> io::Result<()> {
let input: i32 = handle_int_input();
fn debian_choices(input: i32) -> io::Result<()> {
let _ = match input {
1 => install_programs(),
@@ -78,9 +81,7 @@ fn debian_choices() -> io::Result<()> {
Ok(())
}
fn fedora_choices() -> io::Result<()> {
let input: i32 = handle_int_input();
fn fedora_choices(input: i32) -> io::Result<()> {
let _ = match input {
1 => install_programs(),
@@ -113,7 +114,7 @@ fn install_programs() -> Result<(), Box<dyn std::error::Error>> {
let mut chosen: Vec<String> = vec![];
for &n in input.iter() {
if input.contains(&0) {
let _ = main();
return Ok(());
} else {
chosen.push(choice[(n-1) as usize].clone());
}
@@ -135,8 +136,6 @@ fn install_programs() -> Result<(), Box<dyn std::error::Error>> {
}
};
let _ = main();
Ok(())
}
@@ -163,7 +162,7 @@ fn install_flatpaks() -> Result<(), Box<dyn std::error::Error>> {
eprint!("\nInstall Flatpak first? Y/N (1/0)\n");
let input = handle_int_input();
if input == 0 {
let _ = main();
return Ok(());
} else {
match distro {
"arch" => {
@@ -190,7 +189,7 @@ fn install_flatpaks() -> Result<(), Box<dyn std::error::Error>> {
let input = handle_vec_input();
for &n in input.iter() {
if input.contains(&0) {
let _ = main();
return Ok(());
} else if let Some((key, _)) = hashmap.iter().nth((n-1) as usize) {
let status = Command::new("flatpak").arg("install").arg("-y").arg(key).status();
match status {
@@ -207,7 +206,6 @@ fn install_flatpaks() -> Result<(), Box<dyn std::error::Error>> {
eprint!("Error reading file: {}", e);
}
}
let _ = main();
Ok(())
}
@@ -237,7 +235,6 @@ fn update_system() -> Result<(), Box<dyn std::error::Error>> {
_ => eprint!("Unsupported distro")
};
let _ = main();
Ok(())
}
@@ -259,7 +256,7 @@ fn aur() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_current_dir("yay")?;
Command::new("makepkg").arg("-si").status()?;
} else {
let _ = main();
return Ok(());
}
}
@@ -272,7 +269,7 @@ fn aur() -> Result<(), Box<dyn std::error::Error>> {
let mut chosen: Vec<String> = vec![];
for &n in input.iter() {
if input.contains(&0) {
let _ = main();
return Ok(());
} else {
chosen.push(choice[(n-1) as usize].clone());
}
@@ -281,8 +278,6 @@ fn aur() -> Result<(), Box<dyn std::error::Error>> {
Command::new("yay").arg("-S").arg(i).status()?;
}
let _ = main();
Ok(())
}
@@ -329,7 +324,7 @@ fn third_party() -> Result<(), Box<dyn std::error::Error>> {
eprintln!("Script not found: {}", script_name);
}
}
let _ = main();
Ok(())
}
@@ -347,7 +342,7 @@ fn drivers() -> Result<(), Box<dyn Error>> {
let input: i32 = handle_int_input();
if input == 0 {
let _ = main();
return Ok(());
}
match input {
@@ -482,8 +477,6 @@ fn rpm() {
eprintln!("Failed to get Fedora version with status: {}", version.status);
eprintln!("Error output:\n{}", stderr);
}
let _ = main();
}
fn handle_vec_input() -> Vec<i32> {