Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make get_full_help take &dyn Command #12903

Merged
merged 5 commits into from
May 19, 2024

Conversation

IanManske
Copy link
Member

@IanManske IanManske commented May 19, 2024

Description

Changes get_full_help to take a &dyn Command instead of multiple arguments (&Signature, &Examples is_parser_keyword). All of these arguments can be gathered from a Command, so there is no need to pass the pieces to get_full_help.

This PR also fixes an issue where the search terms are not shown if --help is used on a command.

Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good simplification to me. How does this affect custom subcommands? Are they applied correctly (since they seem to not use the Command paradigm in a few ways)

@IanManske
Copy link
Member Author

It looks like custom sub commands like to format and custom commands in modules still show doc comments for the command and arguments + flags.

I believe the only quick with custom commands is that they can't be run directly with Command::run.

src/command.rs Outdated Show resolved Hide resolved
let b_distance = levenshtein_distance(line, &b.name);
a_distance.cmp(&b_distance)
});
commands.sort_by_cached_key(|decl| levenshtein_distance(line, decl.name()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds clever

&self,
include_hidden: bool,
) -> impl Iterator<Item = (Vec<u8>, DeclId)> {
pub fn get_decls_sorted(&self, include_hidden: bool) -> Vec<(Vec<u8>, DeclId)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense with the current implementation, if we have to allocate for the deduping and sorting anyways.

(the question if HashMap then Vec sort beats out the BTreeMap is one of those "what is the real data you run it with anyways" perf questions)

@sholderbach sholderbach merged commit baeba19 into nushell:main May 19, 2024
15 checks passed
@hustcer hustcer added this to the v0.94.0 milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants