Skip to content

Single dash passed as positional arg disappears #381

Open

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.

Activity

  1. markus456 commented on Aug 12, 2021

    @markus456

    So far the only workaround I've found is to use '"-"' as the argument. This preserves it as a positional argument.

  2. shadowspawn commented on Mar 12, 2023

    @shadowspawn
    Member

    This may be an issue in yargs rather than yargs-parser. There is a test that dash is supported as a positional in yargs-parser:

    it('should set - as a non-hyphenated value', function () {

    Related: yargs/yargs#1312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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