75lb / command-line-args

A mature, feature-complete library to parse command-line options.
MIT License
679 stars 107 forks source link

fails to parse string argument with EOL #102

Closed beckend closed 4 years ago

beckend commented 5 years ago

"--script=require('ts-node').register({transpileOnly: true})\nrequire('/tmp/fork/server-fork.ts')"

yargs yields: require('ts-node').register({transpileOnly: true})\nrequire('/tmp/fork/server-fork.ts')

command-line-args: require('ts-node').register({transpileOnly: true})

75lb commented 4 years ago

Hi, could you post some code I can run to reproduce this issue please.

beckend commented 4 years ago

Use the "--script=require('ts-node').register({transpileOnly: true})\nrequire('/tmp/fork/server-fork.ts')"

and parse it, your script argument should be what yargs gives but does not handle \n

75lb commented 4 years ago

Hi, i need code please so I can see your optionDefinitions - you just repeated your original post which didn't add any new information. I can't reproduce this issue, that's why I asked for a reproduction case - code I can run to reproduce the issue. Also, which OS are you on?

With this code:

const commandLineArgs = require('command-line-args')

const optionDefinitions = [
  { name: 'script' }
]

const options = commandLineArgs(optionDefinitions)
console.log(options)

The invocation works correctly on macOS:

$ node example.js "--script=require('ts-node').register({transpileOnly: true})\nrequire('/tmp/fork/server-fork.ts')"
{
  script: "require('ts-node').register({transpileOnly: true})\\nrequire('/tmp/fork/server-fork.ts')"
}

Please post code and an example invocation like the above so I can reproduce your issue, thanks.

beckend commented 4 years ago

I see, well your test looks correct, but then again this was quite I while ago i tested this. My OS is linux, and the EOL charater was imported from

import { EOL } from 'os'
// or
const { EOL } = require('os')

I will close this since it seems not an issue.