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

util: parseArgs - if the option key is not being passed it should also throw an error #48839

Closed
ErickWendel opened this issue Jul 19, 2023 · 2 comments
Labels
util Issues and PRs related to the built-in util module.

Comments

@ErickWendel
Copy link
Member

ErickWendel commented Jul 19, 2023

Version

v21.0.0-pre

Platform

Darwin MacBook-Pro-7.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

Using the code below, it doesn't throw an error if the options are not provided.

// index.mjs
import { parseArgs } from 'node:util'

const { values } = parseArgs({
    strict: true,
    options: {
        file: {
            type: 'string',
            short: 'f'
        },
    },
})
console.log('args:', values)
// args: [Object: null prototype] {}

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

Should throw an error for both missing options and values

What do you see instead?

Only throw for missing values

Additional information

@nodejs/tooling

@bakkot
Copy link

bakkot commented Jul 19, 2023

By "missing options", do you mean that the user of the CLI app doesn't pass the --file option?

If so: in most CLI applications, most options are optional. So that's definitely not the correct default; it would need to be opt in. For which, see #44564.

I'm also not sure what you mean by "throw for missing values". This utility doesn't (and shouldn't) throw if the user fails to pass any values; that's also up to you to validate.

@VoltrexKeyva VoltrexKeyva added the util Issues and PRs related to the built-in util module. label Jul 20, 2023
@ErickWendel
Copy link
Member Author

By "missing options", do you mean that the user of the CLI app doesn't pass the --file option?

If so: in most CLI applications, most options are optional. So that's definitely not the correct default; it would need to be opt in. For which, see #44564.

I'm also not sure what you mean by "throw for missing values". This utility doesn't (and shouldn't) throw if the user fails to pass any values; that's also up to you to validate.

Oh this issue you mentioned is exactly what I meant. I'm gonna close it here and keep there! thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

3 participants