forked from extern/nushell
Added help externs
command (#8403)
# Description `help externs` - command, which list external commands Closes https://github.com/nushell/nushell/issues/8301 # User-Facing Changes ```nu $ help externs ╭───┬──────────────┬─────────────┬───────────────────────────────────────────────────╮ │ # │ name │ module_name │ usage │ ├───┼──────────────┼─────────────┼───────────────────────────────────────────────────┤ │ 0 │ git push │ completions │ Push changes │ │ │ │ │ │ │ 1 │ git fetch │ completions │ Download objects and refs from another repository │ │ │ │ │ │ │ 2 │ git checkout │ completions │ Check out git branches and files │ │ │ │ │ │ ╰───┴──────────────┴─────────────┴───────────────────────────────────────────────────╯ ``` # 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` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # 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.
This commit is contained in:
committed by
GitHub
parent
f34ac9be62
commit
4de0347fdc
@ -463,6 +463,52 @@ impl<'e, 's> ScopeData<'e, 's> {
|
||||
sig_records
|
||||
}
|
||||
|
||||
pub fn collect_externs(&self, span: Span) -> Vec<Value> {
|
||||
let mut externals = vec![];
|
||||
for ((command_name, _), decl_id) in &self.commands_map {
|
||||
let decl = self.engine_state.get_decl(**decl_id);
|
||||
|
||||
if decl.is_known_external() {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
|
||||
let mut module_commands = vec![];
|
||||
for module in &self.modules_map {
|
||||
let module_name = String::from_utf8_lossy(module.0).to_string();
|
||||
let module_id = self.engine_state.find_module(module.0, &[]);
|
||||
if let Some(module_id) = module_id {
|
||||
let module = self.engine_state.get_module(module_id);
|
||||
if module.has_decl(command_name) {
|
||||
module_commands.push(module_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cols.push("name".into());
|
||||
vals.push(Value::String {
|
||||
val: String::from_utf8_lossy(command_name).to_string(),
|
||||
span,
|
||||
});
|
||||
|
||||
cols.push("module_name".into());
|
||||
vals.push(Value::String {
|
||||
val: module_commands.join(", "),
|
||||
span,
|
||||
});
|
||||
|
||||
cols.push("usage".to_string());
|
||||
vals.push(Value::String {
|
||||
val: decl.usage().into(),
|
||||
span,
|
||||
});
|
||||
|
||||
externals.push(Value::Record { cols, vals, span })
|
||||
}
|
||||
}
|
||||
|
||||
externals
|
||||
}
|
||||
|
||||
pub fn collect_aliases(&self, span: Span) -> Vec<Value> {
|
||||
let mut aliases = vec![];
|
||||
for (alias_name, alias_id) in &self.aliases_map {
|
||||
|
Reference in New Issue
Block a user