Skip to content

fix: wire --regex-pattern through the CLI (#175)#180

Closed
patchwright wants to merge 1 commit into
un33k:masterfrom
patchwright:fix/cli-regex-pattern
Closed

fix: wire --regex-pattern through the CLI (#175)#180
patchwright wants to merge 1 commit into
un33k:masterfrom
patchwright:fix/cli-regex-pattern

Conversation

@patchwright

Copy link
Copy Markdown

Fixes #175.

Problem

The CLI defines --regex-pattern in parse_args, but slugify_params() never passes regex_pattern to slugify() — every other argument is wired except that one. So the flag is silently dropped:

$ slugify --regex-pattern "[^-a-z0-9_]+" "___This is a test___"
this-is-a-test          # expected: ___this-is-a-test___

(@peter-bloomfield reported it; @jdevera confirmed the missing wiring.)

Fix

Add regex_pattern=args.regex_pattern to the slugify_params() dict. argparse already defaults it to None when the flag is absent, which matches slugify()'s own default, so existing behavior is unchanged.

Tests

  • Added regex_pattern to TestCommandParams.DEFAULTS so test_defaults now covers it.
  • test_regex_pattern: the flag flows through to params.
  • test_regex_pattern_end_to_end: reproduces the exact example from --regex-pattern option ignored by CLI #175 and asserts ___this-is-a-test___.

Both new tests fail on the current main (KeyError / wrong output) and pass with the fix. Full suite: 84 passed.

patchwright added a commit to patchwright/wildlint that referenced this pull request Jun 28, 2026
Distilled from un33k/python-slugify#180: an argparse option whose dest is
never read — the flag parses, then silently vanishes. slugify defined
--regex-pattern but slugify_params forwarded every namespace field except
args.regex_pattern.

Low-FP by construction (default tier):
- only fires when a sibling dest on the same namespace IS read in-file, so
  consumption is local and the gap is a genuine oversight (not cross-file use);
- a "namespace" is a parse_args() result or a param annotated
  argparse.Namespace — definitions-only files (e.g. httpie's definition.py)
  have neither and stay silent;
- bails on vars()/getattr/setattr/hasattr/__dict__/parse_known_args namespaces
  (dests could be consumed by string);
- skips help/version actions and dynamic/SUPPRESS dests.

Validated: fires exactly once (regex_pattern) on real slugify master; 0
findings across 10 real argparse CLIs (black/flask/pip/aws/pytest/cpython/
youtube-dl/httpie/tenacity/mitmproxy) — httpie went 46->0 after restricting
reads to actual namespace variables. 51 tests pass, ruff clean, self-clean.

Co-Authored-By: claude-flow <ruv@ruv.net>
@patchwright

Copy link
Copy Markdown
Author

Closing this in favor of #176. @jdevera got there first by several weeks, and that PR also carries the CHANGELOG entry. Sorry for the duplicate, I should have checked for an existing PR before opening this one. Glad #175 gets fixed either way.

@patchwright patchwright closed this Jul 1, 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.

--regex-pattern option ignored by CLI

1 participant