diff --git a/crates/nu-command/src/experimental/view_source.rs b/crates/nu-command/src/experimental/view_source.rs index 83eea4ca9b..c1e76b61df 100644 --- a/crates/nu-command/src/experimental/view_source.rs +++ b/crates/nu-command/src/experimental/view_source.rs @@ -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())