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 async custom processing support. Add chainArgParserCalls() for configuration. Additionally await thenable implicit and default option values and thenable default argument values #1915

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c6bcf4
Add thenable function
aweebit Jul 25, 2023
9f292ad
Chain parseArg calls when parseAsync() is called
aweebit Jul 25, 2023
d1ac0cd
Improve JSDoc readability for chainArgParserCalls
aweebit Jul 25, 2023
2e7ccd1
Await thenable option and argument values when parseAsync() is called
aweebit Jul 25, 2023
2d0c78f
Leave argument variations test untouched
aweebit Jul 25, 2023
905dac0
Remove redundant checkForUnknownOptions() call
aweebit Jul 25, 2023
dacdde0
Rework _parseArg()
aweebit Jul 26, 2023
b64f298
Simplify overwritten option value handling
aweebit Jul 26, 2023
254865c
Handle thenable errors not only when chaining but only when awaiting
aweebit Jul 26, 2023
e66eda5
Precompute _shouldAwait to avoid repeating costly computation
aweebit Jul 26, 2023
fb48134
Position _parseArg() better
aweebit Jul 26, 2023
c34a839
Inherit _asyncParsing. Do not unset it and _shouldAwait
aweebit Jul 26, 2023
4d65c6c
Simplify _shouldAwait computation
aweebit Jul 26, 2023
679bcb5
Inherit await behavior the commander way
aweebit Jul 27, 2023
ade5f95
Handle overwritten not chained options correctly
aweebit Jul 27, 2023
d5799cb
Aggressively prevent unhandled rejections due to overwritten options
aweebit Jul 27, 2023
f5a0557
Fix linting errors
aweebit Jul 27, 2023
ea25170
Forbid parse() usage with async calls
aweebit Jul 27, 2023
b9643bc
Remove await configuration and unnecessary chain mode
aweebit Jul 27, 2023
385fe48
Warn about incorrect parse() instead of throwing
aweebit Jul 28, 2023
d9dcc57
Separation of concerns: add callback to _parseArg()
aweebit Jul 28, 2023
3e0e305
Position awaiting methods better
aweebit Jul 28, 2023
608d91c
Update life cycle description
aweebit Jul 28, 2023
249a0c6
Update life cycle description: clarify and better match source code
aweebit Jul 28, 2023
bf7e096
Adhere to established dot usage pattern
aweebit Jul 28, 2023
6858bdf
Place async argParser warning better
aweebit Jul 29, 2023
1cf9fed
Add thenable default option value warning
aweebit Jul 29, 2023
aa6f7c9
Unify & place thenable option value warnings better
aweebit Jul 29, 2023
9d6cee0
Fix linting error
aweebit Jul 30, 2023
2d21112
Add missing thenable argument value warnings
aweebit Jul 30, 2023
cb8c30b
Remove NODE_ENV check
aweebit Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/argument.js
Expand Up @@ -16,6 +16,8 @@ class Argument {
this.description = description || '';
this.variadic = false;
this.parseArg = undefined;
/** @type {boolean | undefined} */
this.chained = undefined;
this.defaultValue = undefined;
this.defaultValueDescription = undefined;
this.argChoices = undefined;
Expand Down Expand Up @@ -89,6 +91,18 @@ class Argument {
return this;
}

/**
* When set to `true`, next call to the function provided via `.argParser()` will be chained to its return value if it is thenable.
* When set to `undefined` (the default), only chain when `.parseAsync()` has been called.
*
* @param {boolean | undefined} [chained]
* @return {Argument}
*/
chainArgParserCalls(chained) {
this.chained = chained === undefined ? undefined : !!chained;
return this;
}

/**
* Only allow argument value to be one of choices.
*
Expand Down