Comparing version 6.5.10 to 6.5.11
@@ -173,2 +173,3 @@ /// <reference types="node" /> | ||
private setParsedInfo; | ||
unsetMatchedCommand(): void; | ||
/** | ||
@@ -175,0 +176,0 @@ * Parse argv |
@@ -475,2 +475,6 @@ 'use strict'; | ||
} | ||
unsetMatchedCommand() { | ||
this.matchedCommand = void 0; | ||
this.matchedCommandName = void 0; | ||
} | ||
parse(argv = processArgs, {run = true} = {}) { | ||
@@ -511,2 +515,3 @@ this.rawArgs = argv; | ||
run = false; | ||
this.unsetMatchedCommand(); | ||
} | ||
@@ -516,2 +521,3 @@ if (this.options.version && this.showVersionOnExit) { | ||
run = false; | ||
this.unsetMatchedCommand(); | ||
} | ||
@@ -518,0 +524,0 @@ const parsedArgv = { |
@@ -200,2 +200,3 @@ | ||
private setParsedInfo; | ||
unsetMatchedCommand(): void; | ||
/** | ||
@@ -202,0 +203,0 @@ * Parse argv |
@@ -898,2 +898,6 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
} | ||
unsetMatchedCommand() { | ||
this.matchedCommand = void 0; | ||
this.matchedCommandName = void 0; | ||
} | ||
parse(argv = processArgs, {run = true} = {}) { | ||
@@ -934,2 +938,3 @@ this.rawArgs = argv; | ||
run = false; | ||
this.unsetMatchedCommand(); | ||
} | ||
@@ -939,2 +944,3 @@ if (this.options.version && this.showVersionOnExit) { | ||
run = false; | ||
this.unsetMatchedCommand(); | ||
} | ||
@@ -941,0 +947,0 @@ const parsedArgv = { |
{ | ||
"name": "cac", | ||
"version": "6.5.10", | ||
"version": "6.5.11", | ||
"description": "Simple yet powerful framework for building command-line apps.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -32,2 +32,3 @@ <img width="945" alt="2017-07-26 9 27 05" src="https://user-images.githubusercontent.com/8784712/28623641-373450f4-7249-11e7-854d-1b076dab274d.png"> | ||
- [Supply an array as option value](#supply-an-array-as-option-value) | ||
- [Error Handling](#error-handling) | ||
- [With TypeScript](#with-typescript) | ||
@@ -266,2 +267,21 @@ - [With Deno](#with-deno) | ||
### Error Handling | ||
To handle command errors globally: | ||
```js | ||
try { | ||
// Parse CLI args without running the command | ||
cli.parse(process.argv, { run: false }) | ||
// Run the command yourself | ||
// You only need `await` when your command action returns a Promise | ||
await cli.runMatchedCommand() | ||
} catch (error) { | ||
// Handle error here.. | ||
// e.g. | ||
// console.error(error.stack) | ||
// process.exit(1) | ||
} | ||
``` | ||
### With TypeScript | ||
@@ -268,0 +288,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77989
1913
518