Comparing version 2.0.3 to 2.0.4
@@ -172,3 +172,3 @@ "use strict"; | ||
} | ||
const cmd = getCMD(program, parsedOptions.command); | ||
const cmd = getCMD(program, parsedOptions.command.slice(1)); | ||
if (cmd.run) { | ||
@@ -175,0 +175,0 @@ cmd.run(parsedOptions.options); |
@@ -6,5 +6,2 @@ "use strict"; | ||
function validateParsedOptions(parsedOptions, config, index = 1) { | ||
if (index > parsedOptions.command.length) { | ||
return; | ||
} | ||
if (config.options) { | ||
@@ -59,8 +56,8 @@ for (const option of config.options) { | ||
} | ||
if (index === parsedOptions.command.length) { | ||
return; | ||
} | ||
const cmd = config.commandsByKey | ||
? config.commandsByKey[parsedOptions.command[index]] | ||
: undefined; | ||
if (cmd == null) { | ||
throw new Error(`This should never happen.`); | ||
} | ||
validateParsedOptions(parsedOptions, cmd, index + 1); | ||
@@ -67,0 +64,0 @@ } |
{ | ||
"name": "cmd-args", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A simple command-line argument parser for NodeJS command-line tools.", | ||
@@ -5,0 +5,0 @@ "main": "dist/cmd-args.js", |
@@ -19,3 +19,3 @@ # cmd-args | ||
```typescript | ||
import { createArgParser } from './cmd-args' | ||
import { createArgParser } from 'cmd-args' | ||
@@ -110,7 +110,4 @@ const myParser = createArgParser({ | ||
{ | ||
"command": ["my-cmd"], | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"] | ||
} | ||
"verbose": false, | ||
"input-files": ["file1", "file2"] | ||
} | ||
@@ -129,8 +126,5 @@ ``` | ||
{ | ||
"command": ["my-cmd"], | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
@@ -149,8 +143,5 @@ ``` | ||
{ | ||
"command": ["my-cmd"], | ||
"options": { | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
"verbose": false, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
@@ -169,9 +160,6 @@ ``` | ||
{ | ||
"command": ["my-cmd"], | ||
"options": { | ||
"verbose": true, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
"verbose": true, | ||
"input-files": ["file1", "file2"], | ||
"output-file": "file-out" | ||
} | ||
``` |
@@ -258,3 +258,6 @@ // tslint:disable: no-console | ||
const cmd = getCMD(program, parsedOptions.command) | ||
const cmd = getCMD( | ||
program, | ||
parsedOptions.command.slice(1) | ||
) | ||
@@ -261,0 +264,0 @@ if (cmd.run) { |
@@ -9,6 +9,2 @@ import { CommandInternal, ParsedOptions } from './types' | ||
) { | ||
if (index > parsedOptions.command.length) { | ||
return | ||
} | ||
if (config.options) { | ||
@@ -71,2 +67,6 @@ for (const option of config.options) { | ||
if (index === parsedOptions.command.length) { | ||
return | ||
} | ||
const cmd = config.commandsByKey | ||
@@ -76,7 +76,3 @@ ? config.commandsByKey[parsedOptions.command[index]] | ||
if (cmd == null) { | ||
throw new Error(`This should never happen.`) | ||
} | ||
validateParsedOptions(parsedOptions, cmd, index + 1) | ||
validateParsedOptions(parsedOptions, cmd!, index + 1) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67203
1418
161