mirror of
https://github.com/nushell/nushell
synced 2025-01-15 14:44:14 +00:00
clean up filesystem by moving get_interactive_confirmation into util.rs
This commit is contained in:
parent
1c52919103
commit
297f3ba575
6 changed files with 33 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use super::interactive_helper::get_confirmation;
|
use super::util::get_interactive_confirmation;
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
|
@ -88,7 +88,7 @@ impl Command for Cp {
|
||||||
destination.file_name().unwrap().to_str().unwrap()
|
destination.file_name().unwrap().to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = get_confirmation(prompt)?;
|
let input = get_interactive_confirmation(prompt)?;
|
||||||
|
|
||||||
if !input {
|
if !input {
|
||||||
remove.push(index);
|
remove.push(index);
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
use dialoguer::Input;
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
pub fn get_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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod cd;
|
mod cd;
|
||||||
mod cp;
|
mod cp;
|
||||||
mod interactive_helper;
|
|
||||||
mod ls;
|
mod ls;
|
||||||
mod mkdir;
|
mod mkdir;
|
||||||
mod mv;
|
mod mv;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use super::interactive_helper::get_confirmation;
|
use super::util::get_interactive_confirmation;
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
use nu_protocol::engine::{Command, EvaluationContext};
|
||||||
|
@ -74,7 +74,7 @@ impl Command for Mv {
|
||||||
destination.file_name().unwrap().to_str().unwrap()
|
destination.file_name().unwrap().to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = get_confirmation(prompt)?;
|
let input = get_interactive_confirmation(prompt)?;
|
||||||
|
|
||||||
if !input {
|
if !input {
|
||||||
remove.push(index);
|
remove.push(index);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::env::current_dir;
|
||||||
use std::os::unix::prelude::FileTypeExt;
|
use std::os::unix::prelude::FileTypeExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use super::interactive_helper::get_confirmation;
|
use super::util::get_interactive_confirmation;
|
||||||
|
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
|
@ -134,7 +134,7 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result<Value, ShellError> {
|
||||||
file.1.file_name().unwrap().to_str().unwrap()
|
file.1.file_name().unwrap().to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = get_confirmation(prompt)?;
|
let input = get_interactive_confirmation(prompt)?;
|
||||||
|
|
||||||
if !input {
|
if !input {
|
||||||
remove.push(index);
|
remove.push(index);
|
||||||
|
|
|
@ -3,6 +3,9 @@ use std::path::{Path, PathBuf};
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
use nu_protocol::ShellError;
|
use nu_protocol::ShellError;
|
||||||
|
|
||||||
|
use dialoguer::Input;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FileStructure {
|
pub struct FileStructure {
|
||||||
pub resources: Vec<Resource>,
|
pub resources: Vec<Resource>,
|
||||||
|
@ -79,3 +82,27 @@ pub struct Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue