mirror of
https://github.com/nushell/nushell.git
synced 2025-07-07 18:07:02 +02:00
cp, mv, and rm commands need to support -i flag (#5523)
* restored interactive mode to rm command * removed unnecessary whitespace in rm file * removed unnecessary whitespace in rm file * fixed python-vertualenv build issue * moved interactive logic to utils file * restored interactive mode to cp command * interactive mode for mv wip * finished mv implementation * removed unnecessary whitespace * changed unwrap to expect
This commit is contained in:
@ -97,8 +97,31 @@ pub struct Resource {
|
||||
|
||||
impl Resource {}
|
||||
|
||||
pub fn try_interaction(
|
||||
interactive: bool,
|
||||
prompt_msg: &str,
|
||||
file_name: &str,
|
||||
) -> (Result<Option<bool>, Box<dyn Error>>, bool) {
|
||||
let interaction = if interactive {
|
||||
let prompt = format!("{} '{}'? ", prompt_msg, file_name);
|
||||
match get_interactive_confirmation(prompt) {
|
||||
Ok(i) => Ok(Some(i)),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
};
|
||||
|
||||
let confirmed = match interaction {
|
||||
Ok(maybe_input) => maybe_input.unwrap_or(false),
|
||||
Err(_) => false,
|
||||
};
|
||||
|
||||
(interaction, confirmed)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_interactive_confirmation(prompt: String) -> Result<bool, Box<dyn Error>> {
|
||||
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> {
|
||||
|
Reference in New Issue
Block a user