Skip to content

Allow negative numbers as optional optional arguments and command arguments when unambiguous #2339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2025

Conversation

shadowspawn
Copy link
Collaborator

Problem

It is unexpected when negative numbers don't work as option-arguments or command arguments and require special treatment.

e.g.

test --optional -3 => test --optional=-3
test -12.4 => test -- -12.4

See: #61 #413 #2338

Solution

Allow negative numbers for optional option-arguments and for command arguments.

Like Python, if there are options with digit short flag then don't treat negative numbers as special since they overlap with some options. Keep the behaviour simple and conservative.

Description of what some other libraries do: pkgjs/parseargs#77 (comment)

  • yargs has support for negative numbers
  • Python allows negative numbers for positionals if there are not options that look like negative numbers (Python Arguments containing -)

ChangeLog

  • add: support for negative numbers as option-arguments and command-arguments

@mmkal
Copy link

mmkal commented Mar 17, 2025

Looks good to me! FYI I opened a small PR which could either complement this, or become unnecessary if this gets in, or go in first if it's less controversial - I don't feel strongly: #2341

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Mar 26, 2025
@shadowspawn shadowspawn changed the base branch from master to release/14.x March 26, 2025 05:19
@shadowspawn shadowspawn marked this pull request as ready for review April 6, 2025 03:13
@shadowspawn
Copy link
Collaborator Author

Moved out of draft, ready for review.

@shadowspawn shadowspawn merged commit f6302de into tj:release/14.x Apr 11, 2025
9 checks passed
@shadowspawn shadowspawn deleted the feature/negative-arguments branch April 11, 2025 02:14
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Apr 11, 2025
@shadowspawn shadowspawn added this to the v14.0.0 milestone Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending release Merged into a branch for a future release, but not released yet semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants