fix: Make cancel behaviour as expected
This commit is contained in:
parent
09a6f70487
commit
9ba0a1285c
|
@ -26,9 +26,9 @@ async fn show_menu() -> Result<()> {
|
|||
let menu_response: usize = Select::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Pick an option (use arrow keys to select, enter to confirm)")
|
||||
.items(&[
|
||||
"1. Purge online history items",
|
||||
"2. Open ShareX Website",
|
||||
"3. View source code (GitHub)",
|
||||
"Purge online history items",
|
||||
"Open ShareX Website",
|
||||
"View source code (GitHub)",
|
||||
"Exit",
|
||||
])
|
||||
.default(0)
|
||||
|
|
|
@ -44,18 +44,23 @@ struct Tags {
|
|||
|
||||
pub async fn handler(pathflag: Option<PathBuf>) -> Result<()> {
|
||||
let path = match pathflag {
|
||||
Some(pathflag) => pathflag,
|
||||
None => prompt_history_file().ok_or(eyre::eyre!(
|
||||
"No path provided. Please provide a path to your ShareX history file."
|
||||
))?,
|
||||
Some(pathflag) => Some(pathflag),
|
||||
None => prompt_history_file(),
|
||||
};
|
||||
|
||||
if !PathBuf::from(&path).exists() {
|
||||
let history_file = match path {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
if !PathBuf::from(&history_file).exists() {
|
||||
eprintln!("A valid path was not specified. Please try again.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let history_urls = get_history_urls(path);
|
||||
let history_urls = get_history_urls(history_file);
|
||||
|
||||
delete_urls(history_urls).await?;
|
||||
|
||||
|
@ -96,23 +101,35 @@ fn prompt_history_file() -> Option<PathBuf> {
|
|||
),
|
||||
),
|
||||
2 => {
|
||||
// TODO: While till valid path given or exit?
|
||||
match Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Enter the exact path to your history file")
|
||||
.interact_on(&console::Term::stdout())
|
||||
{
|
||||
Ok(path) => {
|
||||
if !PathBuf::from(&path).exists() {
|
||||
eprintln!("A valid path was not specified. Exiting.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
Some(PathBuf::from(path))
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("An error occurred: {}", e);
|
||||
std::process::exit(1);
|
||||
loop {
|
||||
let input = Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Enter path to history file")
|
||||
.default(default_path.to_str()?.to_string())
|
||||
.interact()
|
||||
.unwrap();
|
||||
let path = PathBuf::from(input);
|
||||
if path.exists() {
|
||||
return Some(path);
|
||||
} else {
|
||||
println!("Invalid path given. Please try again.");
|
||||
}
|
||||
}
|
||||
// match Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
// .with_prompt("Enter the exact path to your history file")
|
||||
// .interact_on(&console::Term::stdout())
|
||||
// {
|
||||
// Ok(path) => {
|
||||
// if !PathBuf::from(&path).exists() {
|
||||
// eprintln!("A valid path was not specified. Exiting.");
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
// Some(PathBuf::from(path))
|
||||
// }
|
||||
// Err(e) => {
|
||||
// eprintln!("An error occurred: {}", e);
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
3 => {
|
||||
println!("Canceling operation...");
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{borrow::Cow, time::Duration};
|
|||
|
||||
lazy_static! {
|
||||
pub static ref SHAREX_URL: &'static str = "https://getsharex.com/";
|
||||
pub static ref REPO_URL: &'static str = "https://github.com/IndyV/sharextend_cli";
|
||||
pub static ref REPO_URL: &'static str = "https://github.com/IndyV/sharextended";
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
|
Loading…
Reference in New Issue