Comments (7)
@hisabimbola @antoniom unfortunately, I thought of a couple edge-cases where the logic for handling quoted strings would break the parse. Specifically if you had a boolean argument configured, followed by a string:
-f "hello world"
in this scenario, if -f
is configured as a boolean, you would end up with "hello world"
in your _
-- which is unexpected behavior and would put the burden of more parsing on the consumer.
I think we should leave this behavior as is, i.e., eating '
and "
-- this is the default behavior of the operating system:
node test.js -f "world-hello"
will result in the following process.argv
:
[ '/Users/benjamincoe/.nvm/versions/node/v7.1.0/bin/node',
'/Users/benjamincoe/bcoe/yargs/test.js',
'-f',
'world-hello' ]
so even if we do add this parsing feature to yargs-parser
the operating system will eat the quotes before they get to the parser.
perhaps start a conversation in our community slack and we can discuss other potential solutions to the problem -- perhaps you could JSON encode the data being passed in?
from yargs-parser.
@bcoe Since this is the default behavior from OS side, its OK for me. Feel free to revert it.
from yargs-parser.
@hisabimbola good catch; looks like somewhere in the parsing process we drop the "
, this is definitely a bug. If you get a chance to dig into this yourself, would happily accept a patch. Either way, will definitely try to get this fixed soon.
from yargs-parser.
Passing an undefined variable as args
to the parser (which happens a mistake in the parser's caller) throws a cryptic message, Should this create another issue?
TypeError: Cannot read property 'match' of undefined
from yargs-parser.
@ilatypov π yeah, would appreciate it if you create an issue specifically related to this.
from yargs-parser.
@bcoe Can I please ask you to again have a look at the case for allowing strings with quotes to be passed? It becomes very important to have it when string with spaces need to be passed.
Consider this scenario
./nodeFile.js -n "my node module"
If I don't use double-quotes with my string, then the OS itself will consider the first word as the argument value. But it doesn't strips them out itself. This comment explains it better.
I completely understand your concern when random string is passed after boolean arguments. But I guess passing string with spaces is a very common case too. And if possible, if the option has type specified as string
, at least allow the double-quotes then?
from yargs-parser.
@malhotraashna please open a new issue with an example of a reproduction in test if possible.
from yargs-parser.
Related Issues (20)
- yargs converts numbers that start with 0x to decimals, even if parse-numbers if false HOT 2
- lib/yargs-parser.ts:687:17 - error TS2571: Object is of type 'unknown'. HOT 5
- Existence of βnumberβ Key in `Options.arrays` Changes Parsing HOT 1
- Not working with single dash - HOT 2
- Default value of `false` doesn't work for `narg: { flag: 0 }` HOT 2
- Please add missing tags HOT 1
- Repeated config arguments results in a confusing error HOT 1
- Option with three or more trailing hyphens parsed as positional argument
- `halt-at-non-option` is incompatible with `unknown-options-as-args`
- array w/ default breaks requiresArg HOT 1
- Version number check fails on Bun HOT 3
- Yargs parser supports a minimum Node.js version
- 21.1.0 has broken typings HOT 6
- Version 21.1.0 breaks "--"-related configuration HOT 14
- `negation-prefix` does not work with `short-option-groups` HOT 1
- Broken build on fresh clone (developer) HOT 1
- Can't build locally HOT 2
- `yargs` doesn't enforce `strictOptions` for options passed without `=` HOT 6
- Incorrect parsing of options with escaped quotes HOT 3
- :robot: Release is at https://github.com/yargs/yargs-parser/releases/tag/yargs-parser-v21.1.1 :sunflower:
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yargs-parser.