Skip to content

Strange implicit camel-case conversion when use both unknown-options-as-args and alias #359

Description

@weareoutman

Given code below:

const result = require("yargs-parser")(
  ["--foo", "bar", "--outDir", "dist"],
  {
    string: ["_", "foo", "out-dir"],
    configuration: {
      "unknown-options-as-args": true 
    }
  }
);

console.log(result);

This will print:

{ _: [ '--outDir', 'dist' ], foo: 'bar' }

In which outDir is parsed as a positional argument. This makes sense because outDir is not presented in string, even though its kebab-case variation presented.

However, when I set an alias for out-dir, It behaves in another way:

const result = require("yargs-parser")(
  ["--foo", "bar", "--outDir", "dist"],
  {
    string: ["_", "foo", "out-dir"],
    configuration: {
      "unknown-options-as-args": true 
    },
    alias: {
      "o": "out-dir"
    }
  }
);

console.log(result);

This will print:

{ _: [], foo: 'bar', outDir: 'dist', o: 'dist', 'out-dir': 'dist' }

In which the former unknown option outDir is parsed as a named argument now. I don't know if there are some implicit conversions under the hood?

If the camel-case conversion is intended, I hope the first example will treat outDir as a known named argument too.

Tested in the current version of yargs-parser@20.2.6

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions