11 Commits

Author SHA1 Message Date
86b8cfcfaa Addition: opts.allowMultipleFlagValues & more accurate return flag types
opts.allowMultipleFlagValues -> returns flag values as array and add duplicate flags to the array instead of picking the last one (eg ["--foo", "hello", "--foo=world!"] -> { foo: ["hello", "world!"] }).
    Flag return types are now typed as Partials if a default is not present and opts.allowMultipleFlagValues is not enabled.
2025-06-15 05:18:54 +02:00
c16dbc7d56 Addition: licence & git repo in package.json 2025-06-15 05:17:03 +02:00
Oxtaly
1b9b9e1312 Addition: flag.acceptsNaturalValue (default behavior unchanged) 2025-05-14 02:57:43 +02:00
Oxtaly
5533706b30 Additions & fixes, mainly filtering options & internal refactors
Additions:
    Filtering!:
        opts.shouldStopParsingFunc(): more information in commit's types.d.ts;
        opts.shouldStopParsingStr: more information in commit's types.d.ts;
        opts.parseFilterFunc(): more information in commit's types.d.ts;
        (tweaked (lookingForFlagVal -> naturalFlagAssignment) to include the flag's type to add onto new argMeta for filtering functions);
    isTypeAssignable()
    assureValidFlagConfigState(): Now guarantees that flag.config is assigned right after runAutomaticBooleanFlagNegation() in the flag branch of arg handling, skipping the need for other flagConfig lookups (as it would be required in one step or another regardless);
    runFlagAssignedValueAssignment(): extracted main code of meta.hasAssignedValue branch into this function (also adjusted to account for flag.isNegated);
    internalFlag.isNegated: set by runAutomaticBooleanFlagNegation(), for refactored boolean flag negation handling;
    internalFlag.type: extracted flagType assignments into guaranteed

Removals:
    internalFlag.lookedupFlagConfig: flag.config is now assured with assureValidFlagConfigState() after runAutomaticBooleanFlagNegation(), and is instead tested against flag.config === null within assureValidFlagConfigState() to avoid repeating getting flag;

Fixes:
    expectType(): Removed unused (and broken) null handling from;
    validateOrDefaultIfUnset(): Fixed passing through to expectType() when setting the default, breaking if the default type isn't the 'required' type (ie: null value defaults);
    opts.lowerCaseFlags now correctly applies to shorthand flags;
    flags with an explicit string type now correctly do not apply opts.resolveFlagValueTypes even if enabled;
    defined boolean type flags that undergo automatic boolean negation (ie: --no-flag) now correctly resolve if there is an input value after it (bug with a defined flag: `['--no-flag', 'hi'] -> { 'no-flag': 'hi' }`);
    Fixed some spelling issues (eg: 2x otps -> opts);

Other:
    Copied StringConsumer from OxLib into index.js
    Moved stage of runAutomaticBooleanFlagNegation() from beginning of flag post arg handling -> pre flag assignments in arg handling, with a small refactor;
        -> Addition of internalFlag.isNegated
    Cleaned up and clarified the purpose of isAssignedValueTypeAssignable() -> assignedValueUncastableTypeError() to externalize the check thanks to new isTypeAssignable();
    Cleaned up and clarified the purpose of unknownFlag() -> unknownFlagError() to externalize the check;
    Main arg handling 'loop' is not a for loop instead of a foreach to allow for a break statement for the new opts.shouldStopParsing* options;

-Note: Other small unmentioned things, and big commit, probably forgot some note-worthy things, mb;
2025-05-13 02:12:12 +02:00
Oxtaly
4876804e6c Addition: otps.addFlagShorthandsAsAliases -> Automatically adds shorthands into aliases, so --f resolves to --flag like -f would (with the shorthand configured as -f) 2025-05-11 22:32:00 +02:00
Oxtaly
815bb52510 Added opts.handleBackslashesForSpecialFlagChars and fixed/clarified the code for backslashes & clarified opts.lowerCaseInputValues & opts.lowerCaseFlagValues descriptions 2025-05-11 21:14:20 +02:00
Oxtaly
49d74d9de5 Added opts.lowerCaseInputValues and opts.lowerCaseFlagValues options & refactored flag processing to no longer use temporary flagVal and flagKey vars 2025-05-11 16:41:12 +02:00
Oxtaly
63e0e6c06a Initial remote commit 2025-05-11 07:20:00 +02:00
Oxtaly
d0076ec294 More appropriate renaming 2025-05-11 06:40:17 +02:00
Oxtaly
ef73c447df Added bigint flag type & negated flag bug fixes due to flag.requiredValue option, some refactors for run<Thing> & some other internal functions & fixed 'ignore' value for opts.behaviorOnInputError & fixed flag values on string typed flags when opts.resolveFlagValueTypes was turned on 2025-05-09 18:07:14 +02:00
Oxtaly
aef5a62455 Initial commit 2025-05-09 15:55:57 +02:00