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

Commit b227608

Browse files
committed
fix: use @anycli/errors
1 parent b17406f commit b227608

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"bugs": "https://github.com/anycli/parser/issues",
77
"dependencies": {},
88
"devDependencies": {
9+
"@anycli/errors": "^0.2.0",
910
"@anycli/tslint": "^0.2.5",
1011
"@heroku/linewrap": "^1.0.0",
1112
"@types/chai": "^4.1.2",

src/errors.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {CLIError} from '@anycli/errors'
2+
13
import {Arg} from './args'
24
import {deps} from './deps'
35
import * as flags from './flags'
@@ -11,7 +13,7 @@ export interface ICLIParseErrorOptions {
1113
}
1214
}
1315

14-
export class CLIParseError extends Error {
16+
export class CLIParseError extends CLIError {
1517
public parse: ICLIParseErrorOptions['parse']
1618

1719
constructor(options: ICLIParseErrorOptions & { message: string }) {

src/parse.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// tslint:disable interface-over-type-literal
22

3+
import {CLIError} from '@anycli/errors'
4+
35
import {Arg} from './args'
46
import * as Errors from './errors'
57
import * as Flags from './flags'
@@ -93,7 +95,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
9395
input = arg.slice(arg[2] === '=' ? 3 : 2)
9496
}
9597
if (!input) {
96-
throw new Error(`Flag --${name} expects a value`)
98+
throw new CLIError(`Flag --${name} expects a value`)
9799
}
98100
this.raw.push({type: 'flag', flag: flag.name, input})
99101
} else {
@@ -149,7 +151,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
149151
const flags = {} as any
150152
for (const token of this._flagTokens) {
151153
const flag = this.input.flags[token.flag]
152-
if (!flag) throw new Error(`Unexpected flag ${token.flag}`)
154+
if (!flag) throw new CLIError(`Unexpected flag ${token.flag}`)
153155
if (flag.type === 'boolean') {
154156
if (token.input === `--no-${flag.name}`) {
155157
flags[token.flag] = false

yarn.lock

+44-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# yarn lockfile v1
33

44

5+
"@anycli/errors@^0.2.0":
6+
version "0.2.0"
7+
resolved "https://registry.yarnpkg.com/@anycli/errors/-/errors-0.2.0.tgz#ee421115dcdb499d76de9d4853718c06e1c5d5f0"
8+
dependencies:
9+
clean-stack "^1.3.0"
10+
fs-extra "^5.0.0"
11+
indent-string "^3.2.0"
12+
strip-ansi "^4.0.0"
13+
wrap-ansi "^3.0.1"
14+
515
"@anycli/tslint@^0.2.5":
616
version "0.2.5"
717
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.5.tgz#63feeb981b11f36326e0cb745c62f51d55c2ed67"
@@ -234,6 +244,10 @@ clean-regexp@^1.0.0:
234244
dependencies:
235245
escape-string-regexp "^1.0.5"
236246

247+
clean-stack@^1.3.0:
248+
version "1.3.0"
249+
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31"
250+
237251
cli-cursor@^2.1.0:
238252
version "2.1.0"
239253
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
@@ -548,6 +562,14 @@ flat-cache@^1.2.1:
548562
graceful-fs "^4.1.2"
549563
write "^0.2.1"
550564

565+
fs-extra@^5.0.0:
566+
version "5.0.0"
567+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
568+
dependencies:
569+
graceful-fs "^4.1.2"
570+
jsonfile "^4.0.0"
571+
universalify "^0.1.0"
572+
551573
fs.realpath@^1.0.0:
552574
version "1.0.0"
553575
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -586,7 +608,7 @@ globby@^5.0.0:
586608
pify "^2.0.0"
587609
pinkie-promise "^2.0.0"
588610

589-
graceful-fs@^4.1.2:
611+
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
590612
version "4.1.11"
591613
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
592614

@@ -648,6 +670,10 @@ imurmurhash@^0.1.4:
648670
version "0.1.4"
649671
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
650672

673+
indent-string@^3.2.0:
674+
version "3.2.0"
675+
resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289"
676+
651677
inflight@^1.0.4:
652678
version "1.0.6"
653679
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
@@ -743,6 +769,12 @@ json-stable-stringify-without-jsonify@^1.0.1:
743769
version "1.0.1"
744770
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
745771

772+
jsonfile@^4.0.0:
773+
version "4.0.0"
774+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
775+
optionalDependencies:
776+
graceful-fs "^4.1.6"
777+
746778
levn@^0.3.0, levn@~0.3.0:
747779
version "0.3.0"
748780
resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
@@ -1245,6 +1277,10 @@ typescript@^2.7.1:
12451277
version "2.7.1"
12461278
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"
12471279

1280+
universalify@^0.1.0:
1281+
version "0.1.1"
1282+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
1283+
12481284
util-deprecate@~1.0.1:
12491285
version "1.0.2"
12501286
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
@@ -1265,6 +1301,13 @@ wordwrap@~1.0.0:
12651301
version "1.0.0"
12661302
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
12671303

1304+
wrap-ansi@^3.0.1:
1305+
version "3.0.1"
1306+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-3.0.1.tgz#288a04d87eda5c286e060dfe8f135ce8d007f8ba"
1307+
dependencies:
1308+
string-width "^2.1.1"
1309+
strip-ansi "^4.0.0"
1310+
12681311
wrappy@1:
12691312
version "1.0.2"
12701313
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 commit comments

Comments
 (0)