mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 06:39:33 +02:00
Add verbose (#5512)
Co-authored-by: Frank Zhang <v-frankz@microsoft.com>
This commit is contained in:
parent
9969fbfbb1
commit
4717ac70fd
@ -44,6 +44,11 @@ impl Command for Cp {
|
|||||||
"copy recursively through subdirectories",
|
"copy recursively through subdirectories",
|
||||||
Some('r'),
|
Some('r'),
|
||||||
)
|
)
|
||||||
|
.switch(
|
||||||
|
"verbose",
|
||||||
|
"do copy in verbose mode (default:false)",
|
||||||
|
Some('v'),
|
||||||
|
)
|
||||||
// TODO: add back in additional features
|
// TODO: add back in additional features
|
||||||
// .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'))
|
// .switch("interactive", "ask user to confirm action", Some('i'))
|
||||||
@ -60,12 +65,14 @@ impl Command for Cp {
|
|||||||
let src: Spanned<String> = call.req(engine_state, stack, 0)?;
|
let src: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||||
let dst: Spanned<String> = call.req(engine_state, stack, 1)?;
|
let dst: Spanned<String> = call.req(engine_state, stack, 1)?;
|
||||||
let recursive = call.has_flag("recursive");
|
let recursive = call.has_flag("recursive");
|
||||||
|
let verbose = call.has_flag("verbose");
|
||||||
|
|
||||||
let path = current_dir(engine_state, stack)?;
|
let path = current_dir(engine_state, stack)?;
|
||||||
let source = path.join(src.item.as_str());
|
let source = path.join(src.item.as_str());
|
||||||
let destination = path.join(dst.item.as_str());
|
let destination = path.join(dst.item.as_str());
|
||||||
|
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
let ctrlc = engine_state.ctrlc.clone();
|
||||||
|
let span = call.head;
|
||||||
|
|
||||||
let sources: Vec<_> = match nu_glob::glob_with(&source.to_string_lossy(), GLOB_PARAMS) {
|
let sources: Vec<_> = match nu_glob::glob_with(&source.to_string_lossy(), GLOB_PARAMS) {
|
||||||
Ok(files) => files.collect(),
|
Ok(files) => files.collect(),
|
||||||
@ -137,17 +144,14 @@ impl Command for Cp {
|
|||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let msg =
|
let msg =
|
||||||
format!("copied {:} to {:}", src.display(), dst.display());
|
format!("copied {:} to {:}", src.display(), dst.display());
|
||||||
result.push(Value::String {
|
result.push(Value::String { val: msg, span });
|
||||||
val: msg,
|
|
||||||
span: call.head,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let error = Value::Error {
|
let error = Value::Error {
|
||||||
error: ShellError::GenericError(
|
error: ShellError::GenericError(
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
Some(call.head),
|
Some(span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
),
|
),
|
||||||
@ -221,10 +225,7 @@ impl Command for Cp {
|
|||||||
match std::fs::copy(&s, &d) {
|
match std::fs::copy(&s, &d) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let msg = format!("copied {:} to {:}", &s.display(), &d.display());
|
let msg = format!("copied {:} to {:}", &s.display(), &d.display());
|
||||||
result.push(Value::String {
|
result.push(Value::String { val: msg, span });
|
||||||
val: msg,
|
|
||||||
span: call.head,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let msg = "Can not copy source".to_string();
|
let msg = "Can not copy source".to_string();
|
||||||
@ -232,7 +233,7 @@ impl Command for Cp {
|
|||||||
error: ShellError::GenericError(
|
error: ShellError::GenericError(
|
||||||
msg,
|
msg,
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
Some(call.head),
|
Some(span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
),
|
),
|
||||||
@ -245,7 +246,11 @@ impl Command for Cp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result.into_iter().into_pipeline_data(ctrlc))
|
if verbose {
|
||||||
|
Ok(result.into_iter().into_pipeline_data(ctrlc))
|
||||||
|
} else {
|
||||||
|
Ok(PipelineData::new(span))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -260,6 +265,11 @@ impl Command for Cp {
|
|||||||
example: "cp -r dir_a dir_b",
|
example: "cp -r dir_a dir_b",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Recursively copy dir_a to dir_b, and print the feedbacks",
|
||||||
|
example: "cp -r -v dir_a dir_b",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Move many files into a directory",
|
description: "Move many files into a directory",
|
||||||
example: "cp *.txt dir_a",
|
example: "cp *.txt dir_a",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user