You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Decide result conventions (includes detailed examples of client use) #38
This repo started out with a plan, which was not immediately clear to new-comers (me!). In trying to clarify the naming, I initiated a change in the results conventions which has not been completed (#12#22#23). So let's regroup and get the naming and README and code all in sync again.
Which convention will we use?
(1) "existence" property in result, which records true for any option used anyhow (and a values property)
(2) flags/values with separate results for flags and values
(3) (combined results is included for comparison with other libraries, not as a contender)
I propose in absence of anyone with strong preference for flags/values that we go back to "existence" conventions. (I think flags/values is perfectly workable, but it was somewhat accidental!)
I wanted to explore what client code would look like for various conventions used in the result of the parse. Here are my client scenarios:
Primary use cases for simple use (no error check because optimistic or strict)
detect boolean flag used
detect withValue option used and get value
Other use cases for bring-your-own validation checks:
detect boolean flag misused
detect withValue option misused
detect option used in any form (valid or invalid, whether specified in withValue or not)
These examples include some behaviours which are under discussion or touched on elsewhere (especially the misuse cases #24 and #25). Most are being discussed separately, so please join those discussions rather than comment on special cases here unless it is relevant to your choice of preferred high level convention.
options: track the existence of an option in parsed args no matter whether used as a flag or with a value
values: option values (plain boolean flags do not have a value)
(I think this is representative of what you intended @darcyclarke. Anyone feel free to correct me if I got it wrong in a way that detracts from the functionality!)
// Primary use cases for simple use (no error check because optimistic or strict).// detect boolean flag usedconst{ options, values }=parseArgs(['--foo']);// { options: { foo: true }, values: {} }constfooUsed=options.foo;// detect withValue option used and get valueconst{ options, values }=parseArgs(['--foo=bar'],{withValue: ['--foo']});// { options: { foo: true }, values: { foo: 'bar' } }constfooUsed=options.foo;constfooValue=values.foo;// Other use cases for bring-your-own validation checks.// detect boolean flag misusedconst{ options, values }=parseArgs(['--foo=bar']);// { options: { foo: true }, values: { foo: 'bar' } }constfooUsageError=/* options.foo && */values.foo!==undefined;// detect withValue option misusedconst{ options, values }=parseArgs(['--foo'],{withValue: ['--foo']});// { options: { foo: true }, values: {} }constfooUsageError=options.foo&&values.foo===undefined;// detect option used in any form (valid or invalid, whether specified in withValue or not)const{ options, values }=parseArgs(mysteryArgs,mysteryOptions);constfooUsed=options.foo;
combinedValues storing true for boolean flag, string for value.
// Primary use cases for simple use (no error check because optimistic or strict).// detect boolean flag usedconst{ combinedValues }=parseArgs(['--foo']);// { combinedValues: { foo: true }}constfooUsed=combinedValues.foo;// detect withValue option used and get valueconst{ combinedValues }=parseArgs(['--foo=bar'],{withValue: ['--foo']});// { combinedValues: { foo: 'bar' }}constfooUsed=combinedValues.foo!=undefined;constfooValue=combinedValues.foo;// Other use cases for bring-your-own validation checks.// detect boolean flag misusedconst{ combinedValues }=parseArgs(['--foo=bar']);// { combinedValues: { foo: 'bar' }}constfooUsageError=typeofcombinedValues.foo==='string';// detect withValue option misusedconst{ combinedValues }=parseArgs(['--foo'],{withValue: ['--foo']});// { combinedValues: { foo: true }}constfooUsageError=combinedValues.foo===true;// detect option used in any form (valid or invalid, whether specified in withValue or not)const{ combinedValues }=parseArgs(mysteryArgs,mysteryOptions);constfooUsed=combinedValues.foo!==undefined;
changed the title [-]Exploring result conventions and client use[/-][+]Decide result conventions (includes detailed examples of client use)[/+]on Jan 24, 2022
Activity
shadowspawn commentedon Jan 20, 2022
(1) Existence
Based on original approach for this repo:
options: track the existence of an option in parsed args no matter whether used as a flag or with a valuevalues: option values (plain boolean flags do not have a value)(I think this is representative of what you intended @darcyclarke. Anyone feel free to correct me if I got it wrong in a way that detracts from the functionality!)
Reference comments:
shadowspawn commentedon Jan 20, 2022
(2) flags/values
This is the exclusive
flags/valuesapproach.shadowspawn commentedon Jan 20, 2022
(3) Combined values
combinedValuesstoring true for boolean flag, string for value.shadowspawn commentedon Jan 21, 2022
bcoe commentedon Jan 22, 2022
shadowspawn commentedon Jan 22, 2022
shadowspawn commentedon Jan 22, 2022
bcoe commentedon Jan 23, 2022
[-]Exploring client usage of parse results[/-][+]Exploring result conventions and client use[/+]shadowspawn commentedon Jan 23, 2022
[-]Exploring result conventions and client use[/-][+]Decide result conventions (includes detailed examples of client use)[/+]shadowspawn commentedon Jan 24, 2022
shadowspawn commentedon Feb 27, 2022
Didn't get much feedback on this. Closing in favour of #70 with new proposal.