Skip to content

Add check for implies argument type #1852

@canopy-js-user

Description

@canopy-js-user

Hi there, twice I've accidentally written a line of code like this:

.addOption(new Option(
    '--port <number>', 
    'Which port to run the server on for sync mode'
).default(undefined).implies('sync'))

Ie, I want the --port option to imply the boolean flag sync. However, sync is expecting an object of implied key-value pairs. However, as is, this fails silently and converts the string/array 'sync' into an object, and merges it with the rest of the options:

{
  '0': 's',
  '1': 'y',
  '2': 'n',
  '3': 'c',
  editor: true,
  logging: true,
  open: true,
  backup: true,
  sync: true,
  port: '4004'
}

I'm proposing a check that the argument to implies is an object and not a string, and if it is a string, error. (Or, interpret the string as the name of a boolean option that the programmer is asserting should be true.)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions