Normalize flag names at the pflag level.#18642
Merged
arthurschreiber merged 14 commits intovitessio:mainfrom Sep 15, 2025
Merged
Normalize flag names at the pflag level.#18642arthurschreiber merged 14 commits intovitessio:mainfrom
pflag level.#18642arthurschreiber merged 14 commits intovitessio:mainfrom
Conversation
Instead of defining flags twice (once with underscores, once without), we just normalize them at the `pflag` level. Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Contributor
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
…ke `--tablet_types-to-wait` invalid). Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Otherwise this breaks consumers that e.g. expect output on stdout to be valid JSON. Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Flag variations are handled at the pflag / cobra level via normalization. No need to test them in the unit tests anymore. Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
We call flag parsing directly here, so the dashed/underscored handling is not set up at this point. Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #18642 +/- ##
=========================================
+ Coverage 0 67.53% +67.53%
=========================================
Files 0 1613 +1613
Lines 0 263778 +263778
=========================================
+ Hits 0 178134 +178134
- Misses 0 85644 +85644 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
arthurschreiber
commented
Sep 15, 2025
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
systay
approved these changes
Sep 15, 2025
harshit-gangal
approved these changes
Sep 15, 2025
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.
Description
This pull request changes how we handle the migration from underscored to dashed CLI flags.
Previously, we defined flags twice, once with their new dashed name, and once with the legacy / deprecated underscored name. The underscored name was then marked as deprecated and hidden from things like the help output.
This worked sort of fine for regular flags, as we'd end up reusing the same memory to store the value for either the dashed or underscored flag, so specifying one or the other worked in most cases.
Unfortunately, this approach did not work at all with flags that were bound to Viper. Viper would bind to a specific flag object, and not directly to the pointer where the flag value is stored. Before accessing flag values, Viper would call
.Changedon the flag that was bound, and this would only return true on the flag struct for the exact variant that was specified on the CLI. As Viper can only bind to one flag object, this would break depending on which flag variant Viper was bound to and which flag was passed in via the CLI.We noticed this through CI failures, but users would eventually have noticed that too where deprecated flags would just break / not do anything anymore.
This pull request proposes to fix this using a different approach.
Namely, instead of defining different flag variants, we define flags once, using their dashed variant. Then we define a flag name normalizer function that translates underscored flag names to dashed flag names. This normalizer is called when flags are parsed, so internally we can just standardize on dashed names, while we still support underscored names to be passed to the CLI.
When an underscored name is encountered, we emit a deprecation message (just as before with the multiple flag variants defined).
Because there's only one flag defined, that's the flag we can bind to with Viper, and everything works just as expected.
Related Issue(s)
Checklist
Deployment Notes