I can't find a way to properly configure positional arguments. I have this code:
#!/usr/bin/env node
const create = (argv) => {
console.log('create component with name:', argv.name)
}
const createBuilder = (yargs) => {
yargs.positional('name', {
desc: 'Name of the new component',
})
}
/* eslint-disable no-unused-expressions */
require('yargs')
.command({
command: 'create <name>',
desc: 'Create a new component',
builder: createBuilder,
handler: create,
})
.demandCommand(1, 'A command is required')
.help()
.argv
and I would like to provide a custom error message in case the user doesn't specify a name after the create command.
It's not clear to me from the documentation how to do that, and while going through github issues I came across this comment (#928):
I recommend instead using demandCommand and demandOption (each of which are documented).
These allow you to configure positional arguments and flag arguments separately
I've tried all kinds of combinations with
.demandCommand(1, 'You need to provide name for the new component')
or
.demandOption('name', 'You need to provide name for the new component')
but without luck. Does anybody know how to do this?