Skip to content

Commit

Permalink
Refactor headings (#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored Oct 7, 2023
1 parent 67c9180 commit 03dea00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ add cheese type mozzarella
Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.
So `id` behaves as a boolean option for `--id -5`, but you can use a combined form if needed like `--id=-5`.

For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).

### Required option

Expand Down Expand Up @@ -379,7 +379,7 @@ Options: { number: [ '1', '2', '3' ], letter: true }
Remaining arguments: [ 'operand' ]
```

For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-in-depth.md).

### Version option

Expand Down Expand Up @@ -1131,7 +1131,7 @@ program
There is more information available about:

- [deprecated](./docs/deprecated.md) features still supported for backwards compatibility
- [options taking varying arguments](./docs/options-taking-varying-arguments.md)
- [options taking varying arguments](./docs/options-in-depth.md)
- [parsing life cycle and hooks](./docs/parsing-and-hooks.md)

## Support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Options taking varying numbers of option-arguments
<!-- omit from toc -->
# Options in Depth

The README covers declaring and using options, and mostly parsing will work the way you and your users expect. This page covers some special cases
and subtle issues in depth.
Expand All @@ -8,8 +9,10 @@ and subtle issues in depth.
- [Alternative: Make `--` part of your syntax](#alternative-make-----part-of-your-syntax)
- [Alternative: Put options last](#alternative-put-options-last)
- [Alternative: Use options instead of command-arguments](#alternative-use-options-instead-of-command-arguments)
- [Combining short options, and options taking arguments](#combining-short-options-and-options-taking-arguments)
- [Combining short options as if boolean](#combining-short-options-as-if-boolean)
- [Combining short options, and options taking arguments](#combining-short-options-and-options-taking-arguments)
- [Combining short options as if boolean](#combining-short-options-as-if-boolean)

## Options taking varying numbers of option-arguments

Certain options take a varying number of arguments:

Expand All @@ -20,11 +23,11 @@ program
.option('--test [name...]') // 0 or more
```

This page uses examples with options taking 0 or 1 arguments, but the discussions also apply to variadic options taking more arguments.
This section uses examples with options taking 0 or 1 arguments, but the discussions also apply to variadic options taking more arguments.

For information about terms used in this document see: [terminology](./terminology.md)

## Parsing ambiguity
### Parsing ambiguity

There is a potential downside to be aware of. If a command has both
command-arguments and options with varying option-arguments, this introduces a parsing ambiguity which may affect the user of your program.
Expand Down Expand Up @@ -73,7 +76,7 @@ ingredient: cheese

If you want to avoid your users needing to learn when to use `--`, there are a few approaches you could take.

### Alternative: Make `--` part of your syntax
#### Alternative: Make `--` part of your syntax

Rather than trying to teach your users what `--` does, you could just make it part of your syntax.

Expand All @@ -98,7 +101,7 @@ technique: scrambled
ingredient: cheese
```

### Alternative: Put options last
#### Alternative: Put options last

Commander follows the GNU convention for parsing and allows options before or after the command-arguments, or intermingled.
So by putting the options last, the command-arguments do not get confused with the option-arguments.
Expand All @@ -120,7 +123,7 @@ technique: scrambled
ingredient: cheese
```

### Alternative: Use options instead of command-arguments
#### Alternative: Use options instead of command-arguments

This is a bit more radical, but completely avoids the parsing ambiguity!

Expand Down Expand Up @@ -178,7 +181,7 @@ halal servings: v

If you wish to use options taking varying arguments as boolean options, you need to specify them separately.

```
```console
$ collect -a -v -l
any servings: true
vegan servings: true
Expand All @@ -190,7 +193,7 @@ halal servings: true
Before Commander v5, combining a short option and the value was not supported, and combined short flags were always expanded.
So `-avl` expanded to `-a -v -l`.

If you want backwards compatible behaviour, or prefer combining short options as booleans to combining short option and value,
If you want backwards compatible behaviour, or prefer combining short options as booleans to combining short option and value,
you may change the behavior.

To modify the parsing of options taking an optional value:
Expand Down

0 comments on commit 03dea00

Please sign in to comment.