From 4d4d2f1a424afc0f2fa92cb78aebef4394677387 Mon Sep 17 00:00:00 2001 From: hinto-janaiyo Date: Thu, 24 Nov 2022 21:03:42 -0500 Subject: [PATCH] main: implement [--reset-pools] --- src/constants.rs | 2 +- src/main.rs | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index d2069d8..bf5870a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -171,7 +171,7 @@ r#"USAGE: ./gupax [--flag] --no-startup Disable all auto-startup settings for this instance --reset-state Reset all Gupax state (your settings) --reset-nodes Reset the manual node list in the [P2Pool] tab - --reset-pools Reset the manual pool list in the [XMRig] tab + --reset-pools Reset the manual pool list in the [XMRig] tab --reset-all Reset the state, the manual node list, and the manual pool list --ferris Print an extremely cute crab diff --git a/src/main.rs b/src/main.rs index 3f1a844..a7c1e6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -522,7 +522,14 @@ fn reset_nodes(path: &PathBuf) -> Result<(), TomlError> { } } -fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf) { +fn reset_pools(path: &PathBuf) -> Result<(), TomlError> { + match Pool::create_new(path) { + Ok(_) => { info!("Resetting [pool.toml] ... OK"); Ok(()) }, + Err(e) => { error!("Resetting [pool.toml] ... FAIL ... {}", e); Err(e) }, + } +} + +fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf, pool: &PathBuf) { let mut code = 0; // Attempt to remove directory first match std::fs::remove_dir_all(path) { @@ -542,9 +549,13 @@ fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf) { Ok(_) => (), Err(_) => code = 1, } + match reset_pools(pool) { + Ok(_) => (), + Err(_) => code = 1, + } match code { 0 => println!("\nGupax reset ... OK"), - _ => println!("\nGupax reset ... FAIL"), + _ => eprintln!("\nGupax reset ... FAIL"), } exit(code); } @@ -578,11 +589,12 @@ fn parse_args>(mut app: App, panic: S) -> App { match arg.as_str() { "--state" => { info!("Printing state..."); print_disk_file(&app.state_path); } "--nodes" => { info!("Printing node list..."); print_disk_file(&app.node_path); } - "--reset-state" => if let Ok(()) = reset_state(&app.state_path) { println!("\nState reset ... OK"); exit(0); } else { println!("\nState reset ... FAIL"); exit(1) }, - "--reset-nodes" => if let Ok(()) = reset_nodes(&app.node_path) { println!("\nNode reset ... OK"); exit(0) } else { println!("\nNode reset ... FAIL"); exit(1) }, - "--reset-all" => reset(&app.os_data_path, &app.state_path, &app.node_path), + "--reset-state" => if let Ok(()) = reset_state(&app.state_path) { println!("\nState reset ... OK"); exit(0); } else { eprintln!("\nState reset ... FAIL"); exit(1) }, + "--reset-nodes" => if let Ok(()) = reset_nodes(&app.node_path) { println!("\nNode reset ... OK"); exit(0) } else { eprintln!("\nNode reset ... FAIL"); exit(1) }, + "--reset-pools" => if let Ok(()) = reset_pools(&app.pool_path) { println!("\nPool reset ... OK"); exit(0) } else { eprintln!("\nPool reset ... FAIL"); exit(1) }, + "--reset-all" => reset(&app.os_data_path, &app.state_path, &app.node_path, &app.pool_path), "--no-startup" => app.no_startup = true, - _ => { eprintln!("[Gupax error] Invalid option: [{}]\nFor help, use: [--help]", arg); exit(1); }, + _ => { eprintln!("\n[Gupax error] Invalid option: [{}]\nFor help, use: [--help]", arg); exit(1); }, } } app