Skip to content

coerce not called if option not given #1219

@Nautigsam

Description

@Nautigsam

I have this command definition:

module.exports = {
    command: 'ls [options]',
    describe: 'List tags',
    builder(yargs) {
        yargs
            .option('task', {
                alias: 't',
                describe: 'a task number',
                type: 'string',
                requiresArg: true
            })
            .coerce('task', arg => {
                console.log('AAA: ', arg)
                return arg
            })
            .showHelpOnFail(true)
    },
    async handler(argv) {
        ...
    }
}

But when option --task is not provided, the coerce function is not called. Is it really the expected behaviour? Shouldn't the function be called with undefined nonetheless?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions