Add search functionality to the built-in help command #832
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a cli tool grows in capabilities and complexity it becomes harder and hard to find out which command, subcommand, or option might be helpful to accomplish a task. I'm proposing adding a
--search | -s <term>option to the built in help command which does a textual search of the tree of commands for relevant subcommands, descriptions, options, arguments, etc. It then outputs the relevant search results, highlighting the relevant results in bold.I'd love for some feedback on the approach taken and what kind of changes would be welcome. The changes are largely confined to a new
CommandSearcherstructure which searches the Tree of commands for relevant attributes. I've attempted to have unit tests for the vast majority of the functionality.Simple Examples
Instructions for using the
--search <term>functionality are at the bottom of the help outputCommands that match in name or description are listed at the top:
Options that match are listed below, underneath the command they are associated with:
Example of no results:
Large CLI Examples
Here's a couple examples using
swift-package-managerandswift-formatbuilt against this branch:This is one way of solving #673
Checklist