Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change introduces a pattern-based configuration format for Completely.
The original flat and nested formats remain supported, but pattern config is the
recommended format for new completion files.
Flat and nested config describe completions as pattern-to-suggestions rules:
Pattern config describes the command shape more directly:
The difference is that flat config describes when to suggest words, while pattern config describes commands, options, option values, and positional values.
Improvements
Positional Args Are First-Class
Pattern config treats positional arguments as named values with a position in the command line:
This lets completion distinguish between different positional slots. For example, the completion source for
<source>can be different from the completion source for<dest>.The final positional can also be marked as repeatable:
Only the final positional may be repeatable.
Flags Can Be Interleaved With Positionals
The generated completion script can ignore flags and flag values while calculating the current positional index.
This allows command lines like this to complete correctly:
In flat config, this kind of stateful positional handling requires many wildcard patterns, and quickly becomes difficult to maintain.
Options That Consume Values Are Explicit
Pattern config lets options declare that they consume a value:
This gives the generator useful information:
--branchand-bare aliases for the same option.Options Are Unique By Default
Pattern config treats each option entry as one logical option. After a non-repeatable option is used, neither that option nor its aliases are suggested again. This keeps generated completions from repeatedly offering flags that should normally appear only once.
If an option can appear more than once, it can be marked as repeatable:
Repeatable options are suggested again after they are used, including after their value has been completed.
Aliases Are Grouped Naturally
Command aliases and option aliases can be written together:
This avoids duplicating parallel flat-config entries for each alias.
Option Groups Are Reusable
Pattern config supports named option groups:
These groups keep the file compact while preserving useful structure for the generator.
Token Sources Are Reusable
Completion sources are defined once under
tokensand referenced from patterns or options:This reduces repetition and gives each completion source a stable name.
Token sources use explicit syntax:
+directoryuses a Bash built-in completion action,++filemeans the literal value+file, and a null token source means the token exists but has no suggestions.Broken References Are Validated
Pattern config validates references before generating a script:
[status options]must exist underoptions.<branch>must exist undertokens.This catches common typos early instead of generating a broken completion script.
Better Fit For Bashly Conversion
Bashly already models command-line interfaces in terms of commands, aliases, flags, flag arguments, positional arguments, and allowed values.
Pattern config maps more directly to those concepts than flat config. Bashly now emits this format from its completion builder, including command aliases, option groups, global flags, repeatable flags, repeatable positional args,
allowedvalues, andcompletionssources.Better Extension Point
Pattern config provides explicit places for future completion features without adding more wildcard conventions to flat config. Examples include:
Summary
Flat config is close to generated output: when the command line matches a string pattern, suggest a list of words.
Pattern config is closer to source intent: a command accepts these commands, options, option values, and positional values.
That lets Completely reason about the command line instead of only matching strings.