Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: allow value of ""
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Aug 31, 2018
1 parent d1ef73d commit d027934
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/chai": "^4.1.4",
"@types/mocha": "^5.2.5",
"@types/nock": "^9.3.0",
"@types/node": "^10.9.1",
"@types/node": "^10.9.4",
"@types/node-notifier": "^0.0.28",
"@types/read-pkg": "^3.0.0",
"chai": "^4.1.2",
Expand All @@ -24,7 +24,7 @@
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.1"
"typescript": "^3.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
} else {
input = arg.slice(arg[2] === '=' ? 3 : 2)
}
if (!input) {
if (typeof input !== 'string') {
throw new m.errors.CLIError(`Flag --${name} expects a value`)
}
this.raw.push({type: 'flag', flag: flag.name, input})
Expand Down
9 changes: 9 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ describe('parse', () => {
expect(out.flags).to.deep.equal({myflag: 'foo'})
})

it('parses value of ""', () => {
const out = parse(['-m', ''], {
flags: {
myflag: flags.string({char: 'm'}),
},
})
expect(out.flags).to.deep.equal({myflag: ''})
})

it('requires required flag', () => {
expect(() => {
parse([], {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
version "10.7.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.7.1.tgz#b704d7c259aa40ee052eec678758a68d07132a2e"

"@types/node@^10.9.1":
version "10.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.1.tgz#06f002136fbcf51e730995149050bb3c45ee54e6"
"@types/node@^10.9.4":
version "10.9.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897"

"@types/normalize-package-data@*":
version "2.4.0"
Expand Down Expand Up @@ -1156,9 +1156,9 @@ type-detect@^4.0.0:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"

typescript@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"
typescript@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"

universalify@^0.1.0:
version "0.1.2"
Expand Down

0 comments on commit d027934

Please sign in to comment.