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

Unnecessary arrays in result values? #19

Closed
shadowspawn opened this issue Nov 16, 2021 · 7 comments · Fixed by #42
Closed

Unnecessary arrays in result values? #19

shadowspawn opened this issue Nov 16, 2021 · 7 comments · Fixed by #42
Assignees
Labels
bug Something isn't working

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Nov 16, 2021

const { parseArgs } = require('@pkgjs/parseargs');
const options = {
    withValue: ['foo']
};
const result = parseArgs(undefined, options);
console.log(result.values);

Actual:

 % node withValue.js --flag --foo bar
{ flag: [ undefined ], foo: [ 'bar' ] }

I expect a plain string for foo rather than an array, and no "value" at all for flag.

Expected:

 % node withValue.js --flag --foo bar
{ foo:  'bar'  }
@shadowspawn
Copy link
Collaborator Author

(Happy to fix this, checking my expected behaviour first!)

@ljharb
Copy link
Member

ljharb commented Nov 16, 2021

I’d expect a value of true for flag if it had one at all.

@shadowspawn shadowspawn changed the title Unnecessary arrays in result values Unnecessary arrays in result values? Nov 18, 2021
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Nov 18, 2021

Historical digging. The current implementation was written to match the README description: https://github.com/pkgjs/parseargs#-examples-w-output

As mentioned in: #9 (comment)

The README text was added by @darcyclarke in: 3f057c1

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Nov 18, 2021

For comparison, the "Initial Proposal" has this example. Combined options property in result, no superfluous array wrappers.

 * parseArgs(['--foo', 'bar'], {optionsWithValue: 'foo'})
 *   // {options: {foo: 'bar'}, positionals: []}

@bcoe
Copy link
Collaborator

bcoe commented Dec 4, 2021

I think my expectation would be it's only an array if you set multiples? and if you set multiples, it's an array even if you have only one item?

@bcoe bcoe added the bug Something isn't working label Dec 4, 2021
@ljharb
Copy link
Member

ljharb commented Dec 4, 2021

We should absolutely never have the type of something vary based on whether there's 1 or 2+ items.

@shadowspawn

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants