Skip to content

doc: expand description of parseArg's default #54431

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

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,10 @@ changes:
`false`, values for the option are last-wins. **Default:** `false`.
* `short` {string} A single character alias for the option.
* `default` {string | boolean | string\[] | boolean\[]} The default option
value when it is not set by args. It must be of the same type as the
`type` property. When `multiple` is `true`, it must be an array.
value when this argument is not passed. It must be of the same type as the
`type` property. When `multiple` is `true`, it must be an array. For
`string` arguments, if the option is passed it must still be followed by
a value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`type` property. When `multiple` is `true`, it must be an array. For
`string` arguments, if the option is passed it must still be followed by
a value.
`type` property. When `multiple` is `true`, it must be an array.

In my personal opinion, saying "The default option value when this argument is not passed." implies that if it passed, it must have a value.

Secondly, "it must still be followed by a value." makes it sound like the "default" option doesn't work on string arguments...

Copy link
Contributor Author

@bakkot bakkot Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes it sound like the "default" option doesn't work on string arguments.

The default option doesn't do anything when the option being specified is passed (except in strict: false), so that's a correct inference (as long as you don't skip over the "if the option is passed" part). Unless I'm misunderstanding you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "it must still be followed by a value" is redudant because of "The default option value when this argument is not passed.", but that might just be me.

* `strict` {boolean} Should an error be thrown when unknown arguments
are encountered, or when arguments are passed that do not match the
`type` configured in `options`.
Expand Down