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

Commit

Permalink
fix: use @anycli/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 6, 2018
1 parent b17406f commit b227608
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bugs": "https://github.com/anycli/parser/issues",
"dependencies": {},
"devDependencies": {
"@anycli/errors": "^0.2.0",
"@anycli/tslint": "^0.2.5",
"@heroku/linewrap": "^1.0.0",
"@types/chai": "^4.1.2",
Expand Down
4 changes: 3 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {CLIError} from '@anycli/errors'

import {Arg} from './args'
import {deps} from './deps'
import * as flags from './flags'
Expand All @@ -11,7 +13,7 @@ export interface ICLIParseErrorOptions {
}
}

export class CLIParseError extends Error {
export class CLIParseError extends CLIError {
public parse: ICLIParseErrorOptions['parse']

constructor(options: ICLIParseErrorOptions & { message: string }) {
Expand Down
6 changes: 4 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// tslint:disable interface-over-type-literal

import {CLIError} from '@anycli/errors'

import {Arg} from './args'
import * as Errors from './errors'
import * as Flags from './flags'
Expand Down Expand Up @@ -93,7 +95,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
input = arg.slice(arg[2] === '=' ? 3 : 2)
}
if (!input) {
throw new Error(`Flag --${name} expects a value`)
throw new CLIError(`Flag --${name} expects a value`)
}
this.raw.push({type: 'flag', flag: flag.name, input})
} else {
Expand Down Expand Up @@ -149,7 +151,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
const flags = {} as any
for (const token of this._flagTokens) {
const flag = this.input.flags[token.flag]
if (!flag) throw new Error(`Unexpected flag ${token.flag}`)
if (!flag) throw new CLIError(`Unexpected flag ${token.flag}`)
if (flag.type === 'boolean') {
if (token.input === `--no-${flag.name}`) {
flags[token.flag] = false
Expand Down
45 changes: 44 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
# yarn lockfile v1


"@anycli/errors@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@anycli/errors/-/errors-0.2.0.tgz#ee421115dcdb499d76de9d4853718c06e1c5d5f0"
dependencies:
clean-stack "^1.3.0"
fs-extra "^5.0.0"
indent-string "^3.2.0"
strip-ansi "^4.0.0"
wrap-ansi "^3.0.1"

"@anycli/tslint@^0.2.5":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.5.tgz#63feeb981b11f36326e0cb745c62f51d55c2ed67"
Expand Down Expand Up @@ -234,6 +244,10 @@ clean-regexp@^1.0.0:
dependencies:
escape-string-regexp "^1.0.5"

clean-stack@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31"

cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
Expand Down Expand Up @@ -548,6 +562,14 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

fs-extra@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -586,7 +608,7 @@ globby@^5.0.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

graceful-fs@^4.1.2:
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

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

indent-string@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289"

inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
Expand Down Expand Up @@ -743,6 +769,12 @@ json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
optionalDependencies:
graceful-fs "^4.1.6"

levn@^0.3.0, levn@~0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
Expand Down Expand Up @@ -1245,6 +1277,10 @@ typescript@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"

universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand All @@ -1265,6 +1301,13 @@ wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"

wrap-ansi@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-3.0.1.tgz#288a04d87eda5c286e060dfe8f135ce8d007f8ba"
dependencies:
string-width "^2.1.1"
strip-ansi "^4.0.0"

wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
Expand Down

0 comments on commit b227608

Please sign in to comment.