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