mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:04:40 +02:00
a new command to query the nushell internals (#3704)
* a new command to query the nushell internals * added signature * a little cleanup
This commit is contained in:
@ -2,7 +2,7 @@ pub(crate) mod block;
|
||||
pub(crate) mod evaluate_args;
|
||||
pub mod evaluator;
|
||||
pub(crate) mod expr;
|
||||
pub(crate) mod internal;
|
||||
pub mod internal;
|
||||
pub(crate) mod operator;
|
||||
pub(crate) mod scope;
|
||||
pub(crate) mod variables;
|
||||
|
@ -65,6 +65,20 @@ impl Scope {
|
||||
output.sorted_by(|k1, _v1, k2, _v2| k1.cmp(k2)).collect()
|
||||
}
|
||||
|
||||
pub fn get_commands_info(&self) -> IndexMap<String, Command> {
|
||||
let mut output: IndexMap<String, Command> = IndexMap::new();
|
||||
|
||||
for frame in self.frames.lock().iter().rev() {
|
||||
for (name, command) in frame.commands.iter() {
|
||||
if !output.contains_key(name) {
|
||||
output.insert(name.clone(), command.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output.sorted_by(|k1, _v1, k2, _v2| k1.cmp(k2)).collect()
|
||||
}
|
||||
|
||||
pub fn get_variable_names(&self) -> Vec<String> {
|
||||
self.get_vars().iter().map(|(k, _)| k.to_string()).collect()
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ mod command_args;
|
||||
mod config_holder;
|
||||
pub mod documentation;
|
||||
mod env;
|
||||
mod evaluate;
|
||||
pub mod evaluate;
|
||||
pub mod evaluation_context;
|
||||
mod example;
|
||||
pub mod filesystem;
|
||||
|
@ -111,9 +111,21 @@ impl WholeStreamCommand for PluginFilter {
|
||||
&self.config.usage
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
&self.config.extra_usage
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_filter(self.path.clone(), args)
|
||||
}
|
||||
|
||||
fn is_plugin(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_builtin(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn run_filter(path: String, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
@ -383,9 +395,21 @@ impl WholeStreamCommand for PluginSink {
|
||||
&self.config.usage
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
&self.config.extra_usage
|
||||
}
|
||||
|
||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
run_sink(self.path.clone(), args)
|
||||
}
|
||||
|
||||
fn is_plugin(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_builtin(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn run_sink(path: String, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
|
@ -47,19 +47,38 @@ pub trait WholeStreamCommand: Send + Sync {
|
||||
}
|
||||
|
||||
// Commands that are not meant to be run by users
|
||||
fn is_internal(&self) -> bool {
|
||||
fn is_private(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
// This is a built-in command
|
||||
fn is_builtin(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// Is a sub command
|
||||
fn is_sub(&self) -> bool {
|
||||
self.name().contains(' ')
|
||||
}
|
||||
|
||||
// Is a plugin command
|
||||
fn is_plugin(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
// Is a custom command i.e. def blah [] { }
|
||||
fn is_custom(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// Custom commands are blocks, so we can use the information in the block to also
|
||||
// implement a WholeStreamCommand
|
||||
#[allow(clippy::suspicious_else_formatting)]
|
||||
|
||||
impl WholeStreamCommand for Arc<Block> {
|
||||
fn name(&self) -> &str {
|
||||
&self.params.name
|
||||
@ -73,6 +92,10 @@ impl WholeStreamCommand for Arc<Block> {
|
||||
&self.params.usage
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
&self.params.extra_usage
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let call_info = args.call_info.clone();
|
||||
|
||||
@ -184,13 +207,21 @@ impl WholeStreamCommand for Arc<Block> {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_internal(&self) -> bool {
|
||||
fn is_private(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn is_custom(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_builtin(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -228,6 +259,10 @@ impl Command {
|
||||
self.0.usage()
|
||||
}
|
||||
|
||||
pub fn extra_usage(&self) -> &str {
|
||||
self.0.extra_usage()
|
||||
}
|
||||
|
||||
pub fn examples(&self) -> Vec<Example> {
|
||||
self.0.examples()
|
||||
}
|
||||
@ -260,13 +295,29 @@ impl Command {
|
||||
self.0.is_binary()
|
||||
}
|
||||
|
||||
pub fn is_internal(&self) -> bool {
|
||||
self.0.is_internal()
|
||||
pub fn is_private(&self) -> bool {
|
||||
self.0.is_private()
|
||||
}
|
||||
|
||||
pub fn stream_command(&self) -> &dyn WholeStreamCommand {
|
||||
&*self.0
|
||||
}
|
||||
|
||||
pub fn is_builtin(&self) -> bool {
|
||||
self.0.is_builtin()
|
||||
}
|
||||
|
||||
pub fn is_sub(&self) -> bool {
|
||||
self.0.is_sub()
|
||||
}
|
||||
|
||||
pub fn is_plugin(&self) -> bool {
|
||||
self.0.is_plugin()
|
||||
}
|
||||
|
||||
pub fn is_custom(&self) -> bool {
|
||||
self.0.is_custom()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn whole_stream_command(command: impl WholeStreamCommand + 'static) -> Command {
|
||||
|
Reference in New Issue
Block a user