Skip to content

feat(flag_groups): use pattern syntax for flag group definitions, support bool flags and value constraints#300

Merged
fohte merged 3 commits intomainfrom
fohte/flag-groups-v2
Apr 12, 2026
Merged

feat(flag_groups): use pattern syntax for flag group definitions, support bool flags and value constraints#300
fohte merged 3 commits intomainfrom
fohte/flag-groups-v2

Conversation

@fohte
Copy link
Copy Markdown
Owner

@fohte fohte commented Apr 12, 2026

Why

  • Flag group definitions lack information about whether a flag takes a value, leaving bool flags unsupported
  • <flag:name> * in a pattern consumes * as the flag's value pattern, requiring an extra * for remaining-token absorption (<flag:name> * *), which is confusing

What

  • Change flag_groups definition format from arrays to pattern strings

Before:

definitions:
  flag_groups:
    field-flag: ["-f", "-F", "--field", "--raw-field"]
rules:
  - allow: 'gh api graphql <flag:field-flag> * *'

After:

definitions:
  flag_groups:
    field-flag: "-f|-F|--field|--raw-field *"  # value flag
    verbose: "-v|--verbose"                    # bool flag
    method: "-X|--method GET|HEAD|OPTIONS"     # value-restricted flag
rules:
  - allow: 'gh api graphql <flag:field-flag> *'
  • Definition strings reuse the same syntax as rule patterns, consolidating flag type (value/bool) and value constraints in one place
  • <flag:name> no longer consumes the next token as a value pattern, making patterns more intuitive

Open with Devin

fohte and others added 2 commits April 12, 2026 19:51
intent(flag_groups): encode flag type (value vs bool) and value
  restrictions directly in the definition string, removing the need
  for `<flag:name>` to consume a trailing value pattern token
decision(flag_groups): reuse the existing pattern syntax (pipe-separated
  aliases + optional value pattern) so users learn one notation
  for both rules and definitions
learned(flag_groups): the old `<flag:name> VALUE_PATTERN` design forced
  `*` to serve double duty as both value capture and remaining-args
  wildcard, making patterns like `<flag:name> * *` confusing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sing

intent(flag_groups): eliminate duplicated parsing logic between
  `parse_flag_group_definition` and the rule pattern parser
decision(flag_groups): pass definition strings through the existing
  `build_pattern_tokens` with `inside_group = true` so that trailing
  `*` is consumed as a value pattern, then extract aliases and value
  from the resulting `FlagWithValue` or `Alternation` token

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors flag group definitions from arrays to pattern strings, enabling support for boolean flags and value-restricted matching. The flag:name placeholder is now standalone in rule patterns, as its value-handling behavior is derived from the group's definition. Feedback was provided regarding the performance overhead of parsing these definition strings repeatedly during the matching process, suggesting they be parsed once and cached.

Comment thread src/rules/pattern_matcher/mod.rs Outdated
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment thread docs/src/content/docs/releases/next.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 82.38994% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.05%. Comparing base (58cad03) to head (cc62f6b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/pattern_parser.rs 72.34% 13 Missing ⚠️
src/rules/pattern_matcher/mod.rs 85.48% 9 Missing ⚠️
src/config/model.rs 86.04% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
- Coverage   89.13%   89.05%   -0.08%     
==========================================
  Files          53       53              
  Lines       11603    11665      +62     
==========================================
+ Hits        10342    10388      +46     
- Misses       1261     1277      +16     
Flag Coverage Δ
Linux 88.84% <82.38%> (-0.09%) ⬇️
macOS 90.29% <82.38%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

intent(flag_groups): avoid redundant parsing of flag group definition
  strings during pattern matching, which is called repeatedly due to
  backtracking in the recursive match_engine
decision(flag_groups): add a `parsed_flag_groups` field to Definitions
  populated eagerly after config load/merge/validate, keeping the
  parse-once-use-many pattern without changing match_engine's signature

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fohte fohte merged commit ec284c3 into main Apr 12, 2026
11 checks passed
@fohte fohte deleted the fohte/flag-groups-v2 branch April 12, 2026 11:25
@fohte-bot fohte-bot Bot mentioned this pull request Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant