-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split $nu variable into scope commands and simpler $nu (#9487)
# Description This splits off `scope` from `$nu`, creating a set of `scope` commands for the various types of scope you might be interested in. This also simplifies the `$nu` variable a bit. # User-Facing Changes This changes `$nu` to be a bit simpler and introduces a set of `scope` subcommands. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
- Loading branch information
Showing
21 changed files
with
620 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use nu_engine::scope::ScopeData; | ||
use nu_protocol::ast::Call; | ||
use nu_protocol::engine::{Command, EngineState, Stack}; | ||
use nu_protocol::{ | ||
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Type, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct ScopeAliases; | ||
|
||
impl Command for ScopeAliases { | ||
fn name(&self) -> &str { | ||
"scope aliases" | ||
} | ||
|
||
fn signature(&self) -> Signature { | ||
Signature::build("scope aliases") | ||
.input_output_types(vec![(Type::Nothing, Type::Any)]) | ||
.allow_variants_without_examples(true) | ||
.category(Category::Filters) | ||
} | ||
|
||
fn usage(&self) -> &str { | ||
"Output info on the aliases in the current scope." | ||
} | ||
|
||
fn run( | ||
&self, | ||
engine_state: &EngineState, | ||
stack: &mut Stack, | ||
call: &Call, | ||
_input: PipelineData, | ||
) -> Result<PipelineData, ShellError> { | ||
let span = call.head; | ||
let ctrlc = engine_state.ctrlc.clone(); | ||
|
||
let mut scope_data = ScopeData::new(engine_state, stack); | ||
scope_data.populate_all(); | ||
|
||
Ok(scope_data.collect_aliases(span).into_pipeline_data(ctrlc)) | ||
} | ||
|
||
fn examples(&self) -> Vec<Example> { | ||
vec![Example { | ||
description: "Show the aliases in the current scope", | ||
example: "scope aliases", | ||
result: None, | ||
}] | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_examples() { | ||
use crate::test_examples; | ||
|
||
test_examples(ScopeAliases {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use nu_engine::get_full_help; | ||
use nu_protocol::{ | ||
ast::Call, | ||
engine::{Command, EngineState, Stack}, | ||
Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct Scope; | ||
|
||
impl Command for Scope { | ||
fn name(&self) -> &str { | ||
"scope" | ||
} | ||
|
||
fn signature(&self) -> Signature { | ||
Signature::build("scope") | ||
.category(Category::Core) | ||
.input_output_types(vec![(Type::Nothing, Type::String)]) | ||
.allow_variants_without_examples(true) | ||
} | ||
|
||
fn usage(&self) -> &str { | ||
"Commands for getting info about what is in scope." | ||
} | ||
|
||
fn is_parser_keyword(&self) -> bool { | ||
true | ||
} | ||
|
||
fn run( | ||
&self, | ||
engine_state: &EngineState, | ||
stack: &mut Stack, | ||
call: &Call, | ||
_input: PipelineData, | ||
) -> Result<PipelineData, ShellError> { | ||
Ok(Value::String { | ||
val: get_full_help( | ||
&Scope.signature(), | ||
&[], | ||
engine_state, | ||
stack, | ||
self.is_parser_keyword(), | ||
), | ||
span: call.head, | ||
} | ||
.into_pipeline_data()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use nu_engine::scope::ScopeData; | ||
use nu_protocol::ast::Call; | ||
use nu_protocol::engine::{Command, EngineState, Stack}; | ||
use nu_protocol::{ | ||
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Type, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct ScopeCommands; | ||
|
||
impl Command for ScopeCommands { | ||
fn name(&self) -> &str { | ||
"scope commands" | ||
} | ||
|
||
fn signature(&self) -> Signature { | ||
Signature::build("scope commands") | ||
.input_output_types(vec![(Type::Nothing, Type::Any)]) | ||
.allow_variants_without_examples(true) | ||
.category(Category::Filters) | ||
} | ||
|
||
fn usage(&self) -> &str { | ||
"Output info on the commands in the current scope." | ||
} | ||
|
||
fn run( | ||
&self, | ||
engine_state: &EngineState, | ||
stack: &mut Stack, | ||
call: &Call, | ||
_input: PipelineData, | ||
) -> Result<PipelineData, ShellError> { | ||
let span = call.head; | ||
let ctrlc = engine_state.ctrlc.clone(); | ||
|
||
let mut scope_data = ScopeData::new(engine_state, stack); | ||
scope_data.populate_all(); | ||
|
||
Ok(scope_data.collect_commands(span).into_pipeline_data(ctrlc)) | ||
} | ||
|
||
fn examples(&self) -> Vec<Example> { | ||
vec![Example { | ||
description: "Show the commands in the current scope", | ||
example: "scope commands", | ||
result: None, | ||
}] | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_examples() { | ||
use crate::test_examples; | ||
|
||
test_examples(ScopeCommands {}) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
crates/nu-cmd-lang/src/core_commands/scope/engine_stats.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use nu_engine::scope::ScopeData; | ||
use nu_protocol::ast::Call; | ||
use nu_protocol::engine::{Command, EngineState, Stack}; | ||
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type}; | ||
|
||
#[derive(Clone)] | ||
pub struct ScopeEngineStats; | ||
|
||
impl Command for ScopeEngineStats { | ||
fn name(&self) -> &str { | ||
"scope engine-stats" | ||
} | ||
|
||
fn signature(&self) -> Signature { | ||
Signature::build("scope engine-stats") | ||
.input_output_types(vec![(Type::Nothing, Type::Any)]) | ||
.allow_variants_without_examples(true) | ||
.category(Category::Filters) | ||
} | ||
|
||
fn usage(&self) -> &str { | ||
"Output stats on the engine in the current state." | ||
} | ||
|
||
fn run( | ||
&self, | ||
engine_state: &EngineState, | ||
stack: &mut Stack, | ||
call: &Call, | ||
_input: PipelineData, | ||
) -> Result<PipelineData, ShellError> { | ||
let span = call.head; | ||
|
||
let mut scope_data = ScopeData::new(engine_state, stack); | ||
scope_data.populate_all(); | ||
|
||
Ok(scope_data.collect_engine_state(span).into_pipeline_data()) | ||
} | ||
|
||
fn examples(&self) -> Vec<Example> { | ||
vec![Example { | ||
description: "Show the stats on the current engine state", | ||
example: "scope engine-stats", | ||
result: None, | ||
}] | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_examples() { | ||
use crate::test_examples; | ||
|
||
test_examples(ScopeEngineStats {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
mod aliases; | ||
mod command; | ||
mod commands; | ||
mod engine_stats; | ||
mod modules; | ||
mod variables; | ||
|
||
pub use aliases::*; | ||
pub use command::*; | ||
pub use commands::*; | ||
pub use engine_stats::*; | ||
pub use modules::*; | ||
pub use variables::*; |
Oops, something went wrong.