diff --git a/crates/nu-command/src/commands/platform/mod.rs b/crates/nu-command/src/commands/platform/mod.rs index 62b2053b7a..9bc0133852 100644 --- a/crates/nu-command/src/commands/platform/mod.rs +++ b/crates/nu-command/src/commands/platform/mod.rs @@ -6,7 +6,6 @@ mod clip; mod du; mod exec; mod kill; -mod lang; #[cfg(feature = "clipboard-cli")] mod paste; mod pwd; @@ -23,7 +22,6 @@ pub use clip::Clip; pub use du::Du; pub use exec::Exec; pub use kill::Kill; -pub use lang::Lang; #[cfg(feature = "clipboard-cli")] pub use paste::Paste; pub use pwd::Pwd; diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index b12cf4d8f8..8533ad2004 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -69,7 +69,6 @@ pub fn create_default_context(interactive: bool) -> Result &str { - "lang" - } - - fn signature(&self) -> Signature { - Signature::build("lang") - } - - fn usage(&self) -> &str { - "Returns the nushell-lang information" - } - - fn run(&self, args: CommandArgs) -> Result { - let tag = args.call_info.name_tag.clone(); - let full_commands = args.context.scope.get_commands_info(); - let mut cmd_vec_deque = VecDeque::new(); +impl Lang { + pub fn query_commands(scope: &Scope) -> Result, ShellError> { + let tag = Tag::unknown(); + let full_commands = scope.get_commands_info(); + let mut cmd_vec = Vec::new(); for (key, cmd) in full_commands { let mut indexmap = IndexMap::new(); let mut sig = cmd.signature(); @@ -78,18 +66,10 @@ impl WholeStreamCommand for Lang { UntaggedValue::string(cmd.extra_usage().to_string()).into_value(&tag), ); - cmd_vec_deque - .push_back(UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag)); + cmd_vec.push(UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag)); } - Ok(cmd_vec_deque.into_iter().into_output_stream()) - } - fn examples(&self) -> Vec { - vec![Example { - description: "Query command information from Nushell", - example: "lang", - result: None, - }] + Ok(cmd_vec) } } diff --git a/crates/nu-engine/src/evaluate/mod.rs b/crates/nu-engine/src/evaluate/mod.rs index 2a533fe0f0..dbf8b3b6c9 100644 --- a/crates/nu-engine/src/evaluate/mod.rs +++ b/crates/nu-engine/src/evaluate/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod evaluate_args; pub mod evaluator; pub(crate) mod expr; pub mod internal; +pub(crate) mod lang; pub(crate) mod operator; pub(crate) mod scope; pub(crate) mod variables; diff --git a/crates/nu-engine/src/evaluate/variables.rs b/crates/nu-engine/src/evaluate/variables.rs index 44de76cc38..a6c97fabf2 100644 --- a/crates/nu-engine/src/evaluate/variables.rs +++ b/crates/nu-engine/src/evaluate/variables.rs @@ -1,4 +1,7 @@ -use crate::{evaluate::scope::Scope, EvaluationContext}; +use crate::{ + evaluate::{lang, scope::Scope}, + EvaluationContext, +}; use indexmap::IndexMap; use nu_data::config::path::{default_history_path, history_path}; use nu_errors::ShellError; @@ -88,6 +91,12 @@ pub fn nu(scope: &Scope, ctx: &EvaluationContext) -> Result { ); } + let cmd_info = lang::Lang::query_commands(scope); + match cmd_info { + Ok(cmds) => nu_dict.insert_value("lang", UntaggedValue::table(&cmds).into_value(&tag)), + Err(_) => nu_dict.insert_value("lang", UntaggedValue::string("no commands found")), + } + Ok(nu_dict.into_value()) }