Skip to content
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

Add support for variadic options #1250

Merged
merged 13 commits into from
Jun 1, 2020

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Apr 19, 2020

Pull Request

Problem

People would like to be able to use variadic options, an option which can take more than one value from the following arguments.

See #571

Solution

  1. Syntax:
program
   .option('-m, --mods <mod...>'),
   .option('-o, --optional [opts...]')

Being cautious, this makes the change a breaking change in case people have put dots after a comma separated list for example.

  1. If a value or values are specified then the option value is an array.

  2. The first option argument is parsed in the same way as if the ... was not specified.

  3. Subsequent option arguments are processed as for optional options ([value]), so a leading - or -- indicates an option and not a further argument. A lone -- stops the option processing as normal.

  4. The variadic behaviour triggers for stand-alone options with the first value in the next argument, and not for options where the option value is included in the argument.

These do not trigger variadic processing:

$ program -mvalue operand
$ program --optional=value operand
  1. Repeated use of the option will accumulate the values.

These are equivalent:

$ program --mods first second
$ program --mods first --mods second

Example:

$ transpile --include *.js --exclude *.test.js -- operand

ChangeLog

@shadowspawn shadowspawn added enhancement semver: major Releasing requires a major version bump, not backwards compatible labels Apr 19, 2020
@shadowspawn
Copy link
Collaborator Author

Using variadic options will cause some complications for caller to clarify their intent under some circumstances, in similar ways to options with optional values. So I don't want to promote it too much, it should only be used when compelling benefits.

I am thinking it will be mentioned briefly in the README with a longer explanation in a separate document.

- remove ellipsis for symmetry with .arguments
- require word character before dots
@shadowspawn shadowspawn changed the base branch from develop to release/6.x May 30, 2020 08:25
@shadowspawn shadowspawn changed the title WIP: Add support for variadic options Add support for variadic options May 31, 2020
@shadowspawn shadowspawn marked this pull request as ready for review May 31, 2020 06:39
@shadowspawn
Copy link
Collaborator Author

Added README and ready for review.

Fixed a few spelling mistakes as well, so some extra files touched.

Copy link
Collaborator

@abetomo abetomo left a comment

Choose a reason for hiding this comment

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

LGTM!

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Jun 1, 2020
@shadowspawn shadowspawn merged commit 913389f into tj:release/6.x Jun 1, 2020
@shadowspawn shadowspawn deleted the feature/variadic-options branch June 1, 2020 09:36
@shadowspawn shadowspawn added this to the v6.0.0 milestone Jun 20, 2020
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants