From 667947770f702853088e3b0271754bae49a0e148 Mon Sep 17 00:00:00 2001 From: "Angus.Fenying" Date: Fri, 5 Apr 2019 13:02:15 +0800 Subject: [PATCH] Fixed the trailing arguments with quotes. --- CHANGES.md | 6 ++++-- package.json | 2 +- src/lib/GNUParser.ts | 6 +++++- src/samples/02-command.ts | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a875bf9..c818fff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,12 +2,14 @@ [Dep:LRT.Core]: https://github.com/litert/core.js +## v1.0.1 + +- Fixed: The trailing arguments after `--` should be wrapped by quotes. + ## v1.0.0 - Upgraded [`@litert/core`][Dep:LRT.Core] to the v1.0.x. - Refactored the APIs, for more easier usage. -- Added `windows` style options supports. -- Added `go` style options supports. - Added unlimited commands supports. ## v0.2.2 diff --git a/package.json b/package.json index a057c9d..3cb4091 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@litert/clap", - "version": "1.0.0", + "version": "1.0.1", "description": "A simple library for parsing commandline arguments.", "main": "./lib/index.js", "scripts": { diff --git a/src/lib/GNUParser.ts b/src/lib/GNUParser.ts index 6de4a8d..08fe766 100644 --- a/src/lib/GNUParser.ts +++ b/src/lib/GNUParser.ts @@ -527,7 +527,11 @@ class GNUParser extends AbstractParser { pos, -2, "--", - args.splice(pos, args.length - pos).slice(1).join(" ") + args.splice( + pos, args.length - pos + ).map( + (x) => `"${x}"` + ).slice(1).join(" ") ); } diff --git a/src/samples/02-command.ts b/src/samples/02-command.ts index 0e030b4..d09dd3a 100644 --- a/src/samples/02-command.ts +++ b/src/samples/02-command.ts @@ -91,7 +91,7 @@ parser.addOption({ console.log(JSON.stringify( parser.parse([ "help", "login", "-u=fenying", "-p=helloworld!", "-vcfff", - "--", "--username=fff", "--ccc=12313" + "--", "--username=fff", "--ccc=12313", "this is a test" ]), null, 2