Skip to content

Add --no- prefix support for boolean flag negation#52

Merged
privatenumber merged 1 commit intoprivatenumber:developfrom
Rugvip:rugvip/no-prefix-negation
Mar 6, 2026
Merged

Add --no- prefix support for boolean flag negation#52
privatenumber merged 1 commit intoprivatenumber:developfrom
Rugvip:rugvip/no-prefix-negation

Conversation

@Rugvip
Copy link
Contributor

@Rugvip Rugvip commented Mar 4, 2026

Hello @privatenumber! 👋

I've been searching for good simple flag parsers with TypeScript support for adoption in the Backstage project, and cleye caught my... eye 🤦. We're looking at what a potential migration looks like (backstage/backstage#33061 if you're curious, WIP), and overall it's very smooth.

One diff that we spotted was the support for automatic --no- prefixes for boolean flags. It's not a huge deal and we might also implement our own wrapping and deprecation and get rid of support for it, but I wanted to check in here what your appetite for supporting it natively is.

I ended up with the implementation here as a minimal zero-config approach but of course with a bit more opinionation baked in, compared to for example Node.js' allowNegative option for util.parseArgs. I also tried an implementation in cleye directly with a preprocessing step, but that got ugly fast.

Let me know what you think, happy to try other approaches or skip altogether 🙏

@privatenumber
Copy link
Owner

Thanks for this and for the context on the Backstage migration — glad cleye is working well for you.

I like the idea of --no- prefix support, but I'd rather not have it on by default since it changes parsing behavior for everyone. I prototyped it as an opt-in option:

typeFlag({
    verbose: Boolean,
}, argv, { booleanNegation: true })

When enabled, --no-verbose rewrites to --verbose=false before parsing, so last-wins works naturally (--verbose --no-verbose → false, --no-verbose --verbose → true). Only applies to boolean flags — --no-count on a Number flag stays in unknownFlags.

If that sounds good I can push to this PR with the updated approach.

@Rugvip
Copy link
Contributor Author

Rugvip commented Mar 5, 2026

Love it! Indeed I had the same concern, you can push updates to this PR.

Would this manifest as a global option in cleye or a per-flag option? I don't have a strong opinion to be clear, just curious, either works.

@privatenumber privatenumber changed the base branch from develop to beta March 5, 2026 14:07
@privatenumber privatenumber force-pushed the rugvip/no-prefix-negation branch from ba876c1 to e139eb5 Compare March 5, 2026 14:07
@privatenumber
Copy link
Owner

Pushed the updated approach to this PR — rebased on beta and replaced the implementation with booleanNegation option.

For cleye I'll expose it as a global booleanFlagNegation option since it's global here too.

@privatenumber privatenumber force-pushed the rugvip/no-prefix-negation branch from e139eb5 to f462aed Compare March 6, 2026 05:54
@privatenumber privatenumber force-pushed the rugvip/no-prefix-negation branch 2 times, most recently from 8c4c3f2 to 3906bdc Compare March 6, 2026 11:37
@privatenumber privatenumber changed the base branch from beta to develop March 6, 2026 13:54
@privatenumber privatenumber force-pushed the rugvip/no-prefix-negation branch from 3906bdc to f0bfb67 Compare March 6, 2026 13:54
@privatenumber privatenumber merged commit 4e08612 into privatenumber:develop Mar 6, 2026
1 of 2 checks passed
@privatenumber
Copy link
Owner

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@privatenumber
Copy link
Owner

🎉 This PR is included in version 5.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants