mirror of
https://github.com/nushell/nushell
synced 2024-11-10 23:24:14 +00:00
Adds flags and optional arguments to view-source (#5446)
* added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt
This commit is contained in:
parent
02a3430ef0
commit
0b9c0fea9d
1 changed files with 26 additions and 0 deletions
|
@ -52,6 +52,8 @@ impl Command for ViewSource {
|
|||
let decl = engine_state.get_decl(decl_id);
|
||||
let sig = decl.signature();
|
||||
let vec_of_required = &sig.required_positional;
|
||||
let vec_of_optional = &sig.optional_positional;
|
||||
let vec_of_flags = &sig.named;
|
||||
// gets vector of positionals.
|
||||
if let Some(block_id) = decl.get_block_id() {
|
||||
let block = engine_state.get_block(block_id);
|
||||
|
@ -68,6 +70,30 @@ impl Command for ViewSource {
|
|||
final_contents.push_str(&n.shape.to_string());
|
||||
final_contents.push(' ');
|
||||
}
|
||||
for n in vec_of_optional {
|
||||
final_contents.push_str(&n.name);
|
||||
// name of positional arg
|
||||
final_contents.push_str("?:");
|
||||
final_contents.push_str(&n.shape.to_string());
|
||||
final_contents.push(' ');
|
||||
}
|
||||
for n in vec_of_flags {
|
||||
final_contents.push_str("--");
|
||||
final_contents.push_str(&n.long);
|
||||
final_contents.push(' ');
|
||||
if n.short.is_some() {
|
||||
final_contents.push_str("(-");
|
||||
final_contents.push(n.short.expect("this cannot trigger."));
|
||||
final_contents.push(')');
|
||||
}
|
||||
if n.arg.is_some() {
|
||||
final_contents.push_str(": ");
|
||||
final_contents.push_str(
|
||||
&n.arg.as_ref().expect("this cannot trigger.").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())
|
||||
|
|
Loading…
Reference in a new issue