move lang command to $nu (#3720)

This commit is contained in:
Darren Schroeder 2021-07-01 13:09:50 -05:00 committed by GitHub
parent 17008bb648
commit 9a1e1d5b1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 33 deletions

View file

@ -6,7 +6,6 @@ mod clip;
mod du; mod du;
mod exec; mod exec;
mod kill; mod kill;
mod lang;
#[cfg(feature = "clipboard-cli")] #[cfg(feature = "clipboard-cli")]
mod paste; mod paste;
mod pwd; mod pwd;
@ -23,7 +22,6 @@ pub use clip::Clip;
pub use du::Du; pub use du::Du;
pub use exec::Exec; pub use exec::Exec;
pub use kill::Kill; pub use kill::Kill;
pub use lang::Lang;
#[cfg(feature = "clipboard-cli")] #[cfg(feature = "clipboard-cli")]
pub use paste::Paste; pub use paste::Paste;
pub use pwd::Pwd; pub use pwd::Pwd;

View file

@ -69,7 +69,6 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
whole_stream_command(Benchmark), whole_stream_command(Benchmark),
// Metadata // Metadata
whole_stream_command(Tags), whole_stream_command(Tags),
whole_stream_command(Lang),
// Shells // Shells
whole_stream_command(Next), whole_stream_command(Next),
whole_stream_command(Previous), whole_stream_command(Previous),

View file

@ -1,28 +1,16 @@
use crate::prelude::*; use crate::Scope;
use indexmap::IndexMap; use indexmap::IndexMap;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::{Dictionary, Signature, UntaggedValue, Value}; use nu_protocol::{Dictionary, Signature, UntaggedValue, Value};
use nu_source::Tag;
pub struct Lang; pub struct Lang;
impl WholeStreamCommand for Lang { impl Lang {
fn name(&self) -> &str { pub fn query_commands(scope: &Scope) -> Result<Vec<Value>, ShellError> {
"lang" let tag = Tag::unknown();
} let full_commands = scope.get_commands_info();
let mut cmd_vec = Vec::new();
fn signature(&self) -> Signature {
Signature::build("lang")
}
fn usage(&self) -> &str {
"Returns the nushell-lang information"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let full_commands = args.context.scope.get_commands_info();
let mut cmd_vec_deque = VecDeque::new();
for (key, cmd) in full_commands { for (key, cmd) in full_commands {
let mut indexmap = IndexMap::new(); let mut indexmap = IndexMap::new();
let mut sig = cmd.signature(); let mut sig = cmd.signature();
@ -78,18 +66,10 @@ impl WholeStreamCommand for Lang {
UntaggedValue::string(cmd.extra_usage().to_string()).into_value(&tag), UntaggedValue::string(cmd.extra_usage().to_string()).into_value(&tag),
); );
cmd_vec_deque cmd_vec.push(UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag));
.push_back(UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag));
} }
Ok(cmd_vec_deque.into_iter().into_output_stream())
}
fn examples(&self) -> Vec<Example> { Ok(cmd_vec)
vec![Example {
description: "Query command information from Nushell",
example: "lang",
result: None,
}]
} }
} }

View file

@ -3,6 +3,7 @@ pub(crate) mod evaluate_args;
pub mod evaluator; pub mod evaluator;
pub(crate) mod expr; pub(crate) mod expr;
pub mod internal; pub mod internal;
pub(crate) mod lang;
pub(crate) mod operator; pub(crate) mod operator;
pub(crate) mod scope; pub(crate) mod scope;
pub(crate) mod variables; pub(crate) mod variables;

View file

@ -1,4 +1,7 @@
use crate::{evaluate::scope::Scope, EvaluationContext}; use crate::{
evaluate::{lang, scope::Scope},
EvaluationContext,
};
use indexmap::IndexMap; use indexmap::IndexMap;
use nu_data::config::path::{default_history_path, history_path}; use nu_data::config::path::{default_history_path, history_path};
use nu_errors::ShellError; use nu_errors::ShellError;
@ -88,6 +91,12 @@ pub fn nu(scope: &Scope, ctx: &EvaluationContext) -> Result<Value, ShellError> {
); );
} }
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()) Ok(nu_dict.into_value())
} }