This is with yargs v16.0.1.
Sample code in test.js:
const yargs = require('yargs/yargs')
const {hideBin} = require('yargs/helpers');
const argv = yargs(hideBin(process.argv))
.command('$0 <foo>', 'the default command', (yargs) => {
yargs
.positional('foo', {type: 'string', required: true})
}, (argv) => {
console.log(argv)
})
.argv
Test:
$ node test.js -
{ _: [], '$0': 'test.js', foo: '' }
$ node test.js a
{ _: [], '$0': 'test.js', foo: 'a' }
This is unfortunate, as using - as a filename to mean stdin or stdout is a common convention.