Allow dynamically updating version number and version option flags and description#1933
Allow dynamically updating version number and version option flags and description#1933aweebit wants to merge 4 commits intotj:developfrom
Conversation
The _version and _versionOptionName properties are initialized to undefined in the constructor. The reasoning is - to make them visible when the Command instance is logged into the console before .version() is called, and not only appear after suddenly - to not break anything if the proxy use for consistent option value handling in the legacy setOptionValueWithSource mode suggested in tj#1919 (and previously in tj#1921) is adopted
Storing the Option instance of the version option instead of just its .attributeName() (_versionOptionName) is meaningful for cases when other properties of the instance need to be accessed (not currently the case, but could be in the future).
|
A quick reaction. I don't think being able to call |
The last example in the demo code shows it could be important. Being able to call
If you mean #1923, I updated it a few hours ago so that version option flag conflicts are handled, too. But it solves a different problem. |
| this.optional = flags.includes('['); // A value is optional when the option is specified. | ||
| // variadic test ignores <value,...> et al which might be used to describe custom splitting of single argument | ||
| this.variadic = /\w\.\.\.[>\]]$/.test(flags); // The option can take multiple values. | ||
| this.setFlagsAndDescription(flags, description); |
There was a problem hiding this comment.
I was quite surprised this refactor did not break the typescript-checkJS run-script. At one time I am pretty sure we were getting errors for JavaScript properties which were not declared/set in the constructor.
TypeScript may have removed that check as too strict for real-world JavaScript.
|
I do not currently want this functionality or refactor of Option, thanks. The I see one commit was initialising ( |
Actually, no. I'll leave it undeclared and deprecate it as moving in the preferred direction. [edit] Opened #1954 |
Problem
Solution
Rework
version()to make all the above examples behave as expected.Includes various improvements to the code for the version option, including the type fix from #1930. For reasoning behind those improvements, see the commit descriptions.
ChangeLog
Added
.version()Fixed
.version()optional parameter typePeer PRs
…solving similar problems
createOption()inhelpOption()to support custom option flag extraction (+ various improvements) #1929 and it's extensions (storing the help option instance in_helpOptioninstead of only the individual flags in_helpShortFlagand_helpLongFlag)