1.4 KiB
1.4 KiB
Command Specification & Navigation (commands/core/spec.go)
The spec module is the "language parser" of IRIS. it understands the relationship between commands, subcommands, and flags.
Data Structures
Spec: The top-level definition (e.g., forgit).Subcommand: Recursively defined children (e.g.,commitundergit).Generator: A function that provides dynamic content (like files or docker IDs).
The Lookup Algorithm
This is the most critical function in IRIS. It follows these steps:
- Tokenization: Splits
"git commit -m"into["git", "commit", "-m"].- Empty tokens (from a trailing space) indicate the user is ready for the next level of suggestions.
- Tree Walking: It starts at the root (
git) and tries to match each following token against the current node's subcommands. - Context Identification: Once it can't walk any further (e.g., a partial word or an option), it defines:
prefix: The path already traveled.partial: The word currently being typed.
- Result Collection: It gathers all valid subcommands and options that match the
partialprefix.
Example
Input: git com
- Tokens:
["git", "com"] - Walk: Root is
git. - Next token
comdoesn't exactly matchcommit. - Stop walking.
partial=com. - Suggestions: Look for subcommands of
gitstarting withcom. - Return:
git commit.