Skip to content

Option always undefined #1769

@NathanC

Description

@NathanC

Options are always showing up as undefined (both in the error message and in my action handler).

I have my program set up like this:

program.command("deploy")
    .description("kick off a deploy")
    .addOption(
        new Option(
            "--only", "perform a partial deploy"
        ).choices(["frontend", "backend"])
    )
    .action((args, options) => console.log("only deploying: " + options.only))
    .parse();

When I try to run this command:
myScript deploy --only frontend

I get this error:
error: option '--only' argument 'undefined' is invalid. Allowed choices are frontend, backend.

If I try it with a disallowed choice (e.g., --only foo), I still get
error: option '--only' argument 'undefined' is invalid. Allowed choices are frontend, backend.

I logged out my argv, and the script is correctly getting all the args:

args:  [
  'C:\\Program Files\\nodejs\\node.exe',
  {script path},
  'deploy',
  '--only',
  'frontend'
]

If I don't pass an only flag at all (e.g, myScript deploy), I get the handler console log statement:
only deploying: undefined

This is happening on Windows, with Node v16.4.2,

Any idea what might be happening? Am I constructing something wrong, or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions