Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single dash passed as positional arg disappears #381

Open
rrthomas opened this issue Apr 26, 2021 · 2 comments
Open

Single dash passed as positional arg disappears #381

rrthomas opened this issue Apr 26, 2021 · 2 comments

Comments

@rrthomas
Copy link

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.

@markus456
Copy link

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

markus456 added a commit to mariadb-corporation/MaxScale that referenced this issue Aug 12, 2021
The Yargs parser doesn't seem to play nicely with option-like arguments
that are passed as positional arguments. For more information, refer to
the following issues:

  yargs/yargs-parser#381
  yargs/yargs-parser#145
  yargs/yargs#1821
@shadowspawn
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants