Skip to content

choices and coerce sequence #756

@Alexsey

Description

@Alexsey

This code

const argv = require('yargs')
  .choices('user', ['Goofy', 'Miky'])
  .coerce('user', user => {
    switch (user) {
      case 'Goofy': return {
        firstName: 'Mark',
        lastName: 'Pipe'
      }
      case 'Miky': return {
        firstName: 'Elon',
        lastName: 'Stone'
      }
    }
  })

will fail because choices will run after coerce. But should it be this way? The obvious purpose of choices is to validate user input but not a generated value. And it would be very good if we will have an opportunity to validate user input and then build some useful value base on it

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions