Skip to content
Myr

Clarify option arguments (#1709)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add more detail about options and option-arguments * Use "greedy" in description

authored by John Gee · committed by GitHub · parent 40e67bc · Browse files · 1 file+17 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−2 removed

  • other:+17 added−2 removed

1 file+17 added−2 removed

modified:Readme.md+17 added-2 removed
176 unmodified lines
177The parsed options can be accessed by calling `.opts()` on a `Command` object, and are passed to the action handler.178179Multi-word options such as "--template-engine" are camel-cased, becoming `program.opts().templateEngine` etc.180181Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).182For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.181An option and its option-argument can be separated by a space, or combined into the same argument. The option-argument can follow the short option directly or follow an `=` for a long option.182183```bash184serve -p 80185serve -p80186serve --port 80187serve --port=80188```189190You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.191192By default options on the command line are not positional, and can be specified before or after other arguments.193
37 unmodified lines
231pizza details:232- cheese233```234235Multiple boolean short options may be combined together following the dash, and may be followed by a single short option taking a value.236For example `-d -s -p cheese` may be written as `-ds -p cheese` or even `-dsp cheese`.237238Options with an expected option-argument are greedy and will consume the following argument whatever the value.239So `--id -xyz` reads `-xyz` as the option-argument.240241`program.parse(arguments)` processes the arguments, leaving any args not consumed by the program options in the `program.args` array. The parameter is optional and defaults to `process.argv`.242243### Default option value244
76 unmodified lines
321$ pizza-options --cheese mozzarella322add cheese type mozzarella323```324325Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.326So `id` behaves as a boolean option for `--id -5`, but you can use a combined form if needed like `--id=-5`.327328For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).329330### Required option331
765 unmodified lines