Skip to content

Trailing and leading quotes - #222

Closed
juergba wants to merge 2 commits into
yargs:masterfrom
juergba:issue/removing-quotes
Closed

juergba wants to merge 2 commits into
yargs:masterfrom
juergba:issue/removing-quotes

Conversation

@juergba

@juergba juergba commented Nov 17, 2019

Copy link
Copy Markdown
Contributor

Description

closes #201

Currently trailing and leading quotes are removed, this applies to string and also to string[] input.

> require('yargs-parser')([ '--arg', '"option"' ])
{ _: [], arg: 'option' }

One (main?) reason for this: --arg "--option"
if user needs --option to be handled as value (no option), he wraps the value into quotes which are removed by yargs-parser later on ==> { _: [], arg: '--option' }
Problem: each and every tl-quotes are removed.

Description of change

This is a delicate topic, so the following is a proposition.

  • we distinguish between string input and string[] input.
    • string: there are good reasons to remove tl-quotes, as does eg Bash.
    • string[]: we never remove any tl-quotes.
  • therefore we move the quote handling from "index.js" to "tokenize-arg-string.js".
  • we introduce the escaped dash '\\-':
    [ '--arg', '\\--option' ] ==> { _: [], arg: '--option' }

BREAKING CHANGE

@juergba juergba changed the title Issue/removing quotes Trailing and leading quotes Nov 17, 2019
Comment thread test/yargs-parser.js
const args = parser('--foo "\\-hello world" --bar="--goodnight moon"')
args.foo.should.equal('-hello world')
args.bar.should.equal('--goodnight moon')
const args2 = parser(['--foo', '\\-hello world', '--bar=--goodnight moon'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the \\ syntax, is there prior art this is based on?

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

Successfully merging this pull request may close these issues.

Trailing and leading quote characters are removed

2 participants