yargs / yargs/yargs-parser

`boolean-negation` + `unknown-options-as-args` strange behaviour

Open
#376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
519
Forks
129
Avg merge
1h 34m
Merged PRs (30d)
1

Description

Node.js: v14.15.2
yargs-parser: v20.2.7

const yargsParser = require('yargs-parser');

const opts = {
  string: ['asd'],
  configuration: {
    'boolean-negation': false,
    'camel-case-expansion': false,
    'unknown-options-as-args': true,
  },
};

console.log(yargsParser('--no-asd2 123', opts));  // { _: [ '--no-asd2', 123 ] }
console.log(yargsParser('--no-asd 123', opts));  // { _: [], 'no-asd': 123 }

Is it correct behaviour? Because of 'boolean-negation': false I was expecting similar output { _: [ '--no-asd', 123 ] }.


Fixed that by adding 'negation-prefix': Math.random().toString(36).slice(2) to configuration. But that would be better to fix it under the hood :) Thanks!


UPD: even 'negation-prefix': '' works fine.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the yargs-parser configuration handling exercised by the Node.js reproduction, focusing on boolean-negation, negation-prefix, and unknown-options-as-args. Run both shown command-line examples and compare their parsed objects; done means the behavior matches the documented configuration expectations without requiring a random negation-prefix workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.