Skip to content

Single dash passed as positional arg disappears #381

@rrthomas

Description

@rrthomas

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.

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