mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Allowed for view-source to include entire custom command definition (#5435)
* allowed for view-source to include entire custom command definition * fmt * clippy
This commit is contained in:
parent
1bcb87c48d
commit
48cf103439
1 changed files with 17 additions and 2 deletions
|
@ -50,12 +50,27 @@ impl Command for ViewSource {
|
||||||
if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) {
|
if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) {
|
||||||
// arg is a command
|
// arg is a command
|
||||||
let decl = engine_state.get_decl(decl_id);
|
let decl = engine_state.get_decl(decl_id);
|
||||||
|
let sig = decl.signature();
|
||||||
|
let vec_of_required = &sig.required_positional;
|
||||||
|
// gets vector of positionals.
|
||||||
if let Some(block_id) = decl.get_block_id() {
|
if let Some(block_id) = decl.get_block_id() {
|
||||||
let block = engine_state.get_block(block_id);
|
let block = engine_state.get_block(block_id);
|
||||||
if let Some(block_span) = block.span {
|
if let Some(block_span) = block.span {
|
||||||
let contents = engine_state.get_span_contents(&block_span);
|
let contents = engine_state.get_span_contents(&block_span);
|
||||||
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
|
let mut final_contents = String::from("def ");
|
||||||
.into_pipeline_data())
|
final_contents.push_str(&val);
|
||||||
|
// The name of the function...
|
||||||
|
final_contents.push_str(" [ ");
|
||||||
|
for n in vec_of_required {
|
||||||
|
final_contents.push_str(&n.name);
|
||||||
|
// name of positional arg
|
||||||
|
final_contents.push(':');
|
||||||
|
final_contents.push_str(&n.shape.to_string());
|
||||||
|
final_contents.push(' ');
|
||||||
|
}
|
||||||
|
final_contents.push_str("] ");
|
||||||
|
final_contents.push_str(&String::from_utf8_lossy(contents));
|
||||||
|
Ok(Value::string(final_contents, call.head).into_pipeline_data())
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::GenericError(
|
Err(ShellError::GenericError(
|
||||||
"Cannot view value".to_string(),
|
"Cannot view value".to_string(),
|
||||||
|
|
Loading…
Reference in a new issue