From 03dea00fe4d9f02ba8634874008c9a7978dd0a4b Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 8 Oct 2023 10:30:31 +1300 Subject: [PATCH] Refactor headings (#2028) --- Readme.md | 6 ++--- ...rying-arguments.md => options-in-depth.md} | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) rename docs/{options-taking-varying-arguments.md => options-in-depth.md} (89%) diff --git a/Readme.md b/Readme.md index f92667d7a..fa9a49a9e 100644 --- a/Readme.md +++ b/Readme.md @@ -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 @@ -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 @@ -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 diff --git a/docs/options-taking-varying-arguments.md b/docs/options-in-depth.md similarity index 89% rename from docs/options-taking-varying-arguments.md rename to docs/options-in-depth.md index 5f661bb33..8e75f30a8 100644 --- a/docs/options-taking-varying-arguments.md +++ b/docs/options-in-depth.md @@ -1,4 +1,5 @@ -# Options taking varying numbers of option-arguments + +# 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. @@ -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: @@ -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. @@ -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. @@ -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. @@ -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! @@ -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 @@ -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: