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 documentation on tricks and traps of using optional options #1332

Merged
merged 12 commits into from
Sep 13, 2020
Prev Previous commit
Next Next commit
Expand fragments a little, reword GNU reference
  • Loading branch information
shadowspawn committed Aug 30, 2020
commit 53cf35be1edf69df8f09f5ff36f0eaa16b48c85e
8 changes: 7 additions & 1 deletion optional-options-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ If you want to avoid your users needing to learn when to use `--`, there are a f
Rather than trying to teach your users what `--` does, you could just make it part of your syntax.

```js
// ...
program.usage('[options] -- [technique]');
program.parse();
```

```sh
Expand All @@ -121,11 +123,13 @@ ingredient: cheese

### Alternative: Put options last

Commander follows the GNU convention for parsing and allows options before or after the command-arguments, or intermingled.
Commander allows options before or after the command-arguments, or even intermixed (like GNU program argument conventions).
So by putting the options last, the command-arguments do not get confused with the option-arguments.

```js
// ...
program.usage('[technique] [options]');
program.parse();
```

```sh
Expand Down Expand Up @@ -155,6 +159,8 @@ program
const ingredient = (options.ingredient === true) ? 'cheese' : options.ingredient;
console.log(`ingredient: ${ingredient}`);
});

program.parse();
```

```sh
Expand Down