mirror of
https://github.com/nushell/nushell.git
synced 2025-07-07 18:07:02 +02:00
clean up filesystem by moving get_interactive_confirmation into util.rs
This commit is contained in:
@ -3,6 +3,9 @@ use std::path::{Path, PathBuf};
|
||||
use nu_path::canonicalize_with;
|
||||
use nu_protocol::ShellError;
|
||||
|
||||
use dialoguer::Input;
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FileStructure {
|
||||
pub resources: Vec<Resource>,
|
||||
@ -79,3 +82,27 @@ pub struct Resource {
|
||||
}
|
||||
|
||||
impl Resource {}
|
||||
|
||||
pub fn get_interactive_confirmation(prompt: String) -> Result<bool, Box<dyn Error>> {
|
||||
let input = Input::new()
|
||||
.with_prompt(prompt)
|
||||
.validate_with(|c_input: &String| -> Result<(), String> {
|
||||
if c_input.len() == 1
|
||||
&& (c_input == "y" || c_input == "Y" || c_input == "n" || c_input == "N")
|
||||
{
|
||||
Ok(())
|
||||
} else if c_input.len() > 1 {
|
||||
Err("Enter only one letter (Y/N)".to_string())
|
||||
} else {
|
||||
Err("Input not valid".to_string())
|
||||
}
|
||||
})
|
||||
.default("Y/N".into())
|
||||
.interact_text()?;
|
||||
|
||||
if input == "y" || input == "Y" {
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user