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:
njbull4
2022-05-18 07:53:46 -07:00
committed by GitHub
parent 9c779b071b
commit 2c58beec13
4 changed files with 147 additions and 60 deletions

View File

@ -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> {