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