mirror of
https://github.com/nushell/nushell.git
synced 2024-12-16 12:12:19 +01:00
-i flag on signaure
This commit is contained in:
parent
ff6cc2cbdd
commit
9ea7cdfc33
@ -29,6 +29,7 @@ impl Command for Cp {
|
||||
"copy recursively through subdirectories",
|
||||
Some('r'),
|
||||
)
|
||||
.switch("interactive", "ask user to confirm action", Some('i'))
|
||||
}
|
||||
|
||||
fn run(
|
||||
@ -39,6 +40,14 @@ impl Command for Cp {
|
||||
) -> Result<Value, ShellError> {
|
||||
let source: String = call.req(context, 0)?;
|
||||
let destination: String = call.req(context, 1)?;
|
||||
let interactive = call.has_flag("interactive");
|
||||
|
||||
if interactive {
|
||||
println!(
|
||||
"Are you shure that you want to move {} to {}?",
|
||||
source, destination
|
||||
);
|
||||
}
|
||||
|
||||
let path: PathBuf = current_dir().unwrap();
|
||||
let source = path.join(source.as_str());
|
||||
|
@ -29,6 +29,8 @@ impl Command for Mv {
|
||||
SyntaxShape::Filepath,
|
||||
"the location to move files/directories to",
|
||||
)
|
||||
.switch("interactive", "ask user to confirm action", Some('i'))
|
||||
.switch("force", "suppress error when no file", Some('f'))
|
||||
}
|
||||
|
||||
fn run(
|
||||
@ -40,6 +42,8 @@ impl Command for Mv {
|
||||
// TODO: handle invalid directory or insufficient permissions when moving
|
||||
let source: String = call.req(context, 0)?;
|
||||
let destination: String = call.req(context, 1)?;
|
||||
let interactive = call.has_flag("interactive");
|
||||
let force = call.has_flag("force");
|
||||
|
||||
let path: PathBuf = current_dir().unwrap();
|
||||
let source = path.join(source.as_str());
|
||||
@ -54,6 +58,21 @@ impl Command for Mv {
|
||||
));
|
||||
}
|
||||
|
||||
if interactive && !force {
|
||||
for file in &sources {
|
||||
println!(
|
||||
"Are you shure that you want to move {} to {}?",
|
||||
file.as_ref()
|
||||
.unwrap()
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
destination.file_name().unwrap().to_str().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (destination.exists() && !destination.is_dir() && sources.len() > 1)
|
||||
|| (!destination.exists() && sources.len() > 1)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ struct RmArgs {
|
||||
trash: bool,
|
||||
permanent: bool,
|
||||
force: bool,
|
||||
interactive: bool,
|
||||
}
|
||||
|
||||
impl Command for Rm {
|
||||
@ -44,6 +45,7 @@ impl Command for Rm {
|
||||
)
|
||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||
.switch("force", "suppress error when no file", Some('f'))
|
||||
.switch("interactive", "ask user to confirm action", Some('i'))
|
||||
.rest(
|
||||
"rest",
|
||||
SyntaxShape::GlobPattern,
|
||||
@ -64,6 +66,7 @@ impl Command for Rm {
|
||||
fn rm(context: &EvaluationContext, call: &Call) -> Result<Value, ShellError> {
|
||||
let trash = call.has_flag("trash");
|
||||
let permanent = call.has_flag("permanent");
|
||||
let interactive = call.has_flag("interactive");
|
||||
|
||||
if trash && permanent {
|
||||
return Err(ShellError::IncompatibleParametersSingle(
|
||||
@ -122,12 +125,22 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result<Value, ShellError> {
|
||||
let recursive = call.has_flag("recursive");
|
||||
let force = call.has_flag("force");
|
||||
|
||||
if interactive && !force {
|
||||
for file in &targets {
|
||||
println!(
|
||||
"Are you shure that you want to delete {}?",
|
||||
file.1.file_name().unwrap().to_str().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let args = RmArgs {
|
||||
targets,
|
||||
recursive,
|
||||
trash,
|
||||
permanent,
|
||||
force,
|
||||
interactive,
|
||||
};
|
||||
let response = rm_helper(call, args);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user