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

Positional options #1427

Merged
merged 26 commits into from
Jan 4, 2021
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0f74c8b
First cut at optionsBeforeArguments
shadowspawn Dec 27, 2020
3de2bde
Different to mix global options and subcommands, and options and argu…
shadowspawn Dec 27, 2020
bc1f8f7
Different to mix global options and subcommands, and options and argu…
shadowspawn Dec 27, 2020
c93da58
Add _parseOptionsFollowingArguments
shadowspawn Dec 27, 2020
69458b4
Use allow wording
shadowspawn Dec 27, 2020
304ad64
Another try at naming
shadowspawn Dec 28, 2020
ee98c44
Exclude options from special processing, which fixes help
shadowspawn Dec 28, 2020
e155f3a
Add help checks for new option configuration
shadowspawn Dec 28, 2020
fe29f6e
Rename after discovering needed for any positional options
shadowspawn Dec 29, 2020
d781d77
Rework logic to hopefully cope with default commands.
shadowspawn Dec 29, 2020
eef4d52
Expand basic tests. Positional options are tricky!
shadowspawn Dec 29, 2020
f20aff0
Add first default command tests
shadowspawn Dec 30, 2020
91468d3
Fill out more tests
shadowspawn Dec 31, 2020
3b6cd3f
Add setters, and throw when passThrough without enabling positional
shadowspawn Jan 1, 2021
bb95593
Rename test file
shadowspawn Jan 1, 2021
9c5b77a
Add TypeScript
shadowspawn Jan 1, 2021
6a4524b
Add tests. Fix help handling by making explicit.
shadowspawn Jan 2, 2021
4d26a15
Reorder tests
shadowspawn Jan 2, 2021
4136ce8
Use usual indentation
shadowspawn Jan 2, 2021
17472b9
Make _enablePositionalOptions inherited to simpify nested commands
shadowspawn Jan 2, 2021
2c9373f
Add examples
shadowspawn Jan 2, 2021
ca47d95
Add tests for some less common setups
shadowspawn Jan 2, 2021
a021878
Test the boring true/false parameters
shadowspawn Jan 2, 2021
7ab4d6d
Fix typo
shadowspawn Jan 2, 2021
71d92e1
Add new section to README with parsing configuration.
shadowspawn Jan 3, 2021
6f7ffcb
Tweak wording in README
shadowspawn Jan 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add TypeScript
shadowspawn committed Jan 1, 2021
commit 9c5b77a902d2ac0dce04c1a9533e6397e37509ba
8 changes: 8 additions & 0 deletions typings/commander-tests.ts
Original file line number Diff line number Diff line change
@@ -147,6 +147,14 @@ const allowUnknownOptionThis2: commander.Command = program.allowUnknownOption(fa
const allowExcessArgumentsThis1: commander.Command = program.allowExcessArguments();
const allowExcessArgumentsThis2: commander.Command = program.allowExcessArguments(false);

// enablePositionalOptions
const enablePositionalOptionsThis1: commander.Command = program.enablePositionalOptions();
const enablePositionalOptionsThis2: commander.Command = program.enablePositionalOptions(false);

// passThroughOptions
const passThroughOptionsThis1: commander.Command = program.passThroughOptions();
const passThroughOptionsThis2: commander.Command = program.passThroughOptions(false);

// parse
const parseThis1: commander.Command = program.parse();
const parseThis2: commander.Command = program.parse(process.argv);
21 changes: 21 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -400,6 +400,27 @@ declare namespace commander {
*/
allowExcessArguments(allowExcess?: boolean): this;

/**
* Enable positional options. Positional means global options are specified before subcommands which lets
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
*
* The default behaviour is non-positional and global options may appear anywhere on the command line.
*
* @returns `this` command for chaining
*/
enablePositionalOptions(positional?: boolean): this;

/**
* Pass through options that come after command-arguments rather than treat them as command-options,
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
* positional options to have been enabled on the program (parent commands).
*
* The default behaviour is non-positional and options may appear before or after command-arguments.
*
* @returns `this` command for chaining
*/
passThroughOptions(passThrough?: boolean): this;

/**
* Parse `argv`, setting options and invoking commands when defined.
*