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 f6ea967 commit b9424dc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require('ts-node/register')
require('../src').run()
.catch(require('../src/handle_error'))
.catch(require('@anycli/errors/handle'))

// const {Command, flags, parse} = require('../src')

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
]
},
"dependencies": {
"@anycli/parser": "^3.2.4"
"@anycli/parser": "^3.2.5"
},
"devDependencies": {
"@anycli/config": "^1.3.2",
"@anycli/config": "^1.3.9",
"@anycli/errors": "^0.2.0",
"@anycli/plugin-help": "^0.6.3",
"@anycli/plugin-not-found": "^0.1.16",
"@anycli/plugin-plugins": "^0.2.12",
"@anycli/tslint": "^0.2.5",
"@anycli/tslint": "^0.2.6",
"@types/chai": "^4.1.2",
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.0",
Expand Down
28 changes: 16 additions & 12 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// tslint:disable no-implicit-dependencies
const pjson = require('../package.json')
import * as Config from '@anycli/config'
import * as Errors from '@anycli/errors'
import * as Parser from '@anycli/parser'
import Help from '@anycli/plugin-help'
import {inspect} from 'util'

import * as flags from './flags'
import {compact} from './util'

export default abstract class Command {
static _base = `${pjson.name}@${pjson.version}`
Expand Down Expand Up @@ -73,10 +74,14 @@ export default abstract class Command {
}
}

exit(code?: number) { throw new Config.ExitError(code || 0) }

log(s?: string | undefined) {
process.stdout.write((s || '') + '\n')
exit(code = 0) { Errors.exit(code) }
warn(input: string | Error) { Errors.warn(input) }
error(input: string | Error, options: {code?: string, exit?: number} = {}) {
Errors.error(input, options)
}
log(message: any = '') {
message = typeof message === 'string' ? message : inspect(message)
process.stdout.write(message + '\n')
}

/**
Expand All @@ -85,13 +90,12 @@ export default abstract class Command {
abstract async run(): Promise<any>
protected async init() {
this.debug('init version: %s argv: %o', this.ctor._base, this.argv)
global['cli-ux'] = global['cli-ux'] || {}
global['cli-ux'].debug = global['cli-ux'].debug || !!this.config.debug
global['cli-ux'].errlog = global['cli-ux'].errlog || this.config.errlog
global['cli-ux'].context = global['cli-ux'].context || {
command: compact([this.id, ...this.argv]).join(' '),
version: this.config.userAgent,
}
if (this.config.debug) Errors.config.debug = true
if (this.config.errlog) Errors.config.errlog = this.config.errlog
// global['cli-ux'].context = global['cli-ux'].context || {
// command: compact([this.id, ...this.argv]).join(' '),
// version: this.config.userAgent,
// }
global['http-call'] = global['http-call'] || {}
global['http-call']!.userAgent = this.config.userAgent
if (this._helpOverride()) return this._help()
Expand Down
2 changes: 1 addition & 1 deletion src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function build<T>(defaults: Partial<IOptionFlag<T>>): Definition<T> {
}

export function option<T>(options: {parse: IOptionFlag<T>['parse']} & Partial<IOptionFlag<T>>) {
return build<T>({optionType: 'custom', ...options})()
return build<T>(options)()
}

const _enum = <T = string>(opts: Parser.flags.EnumFlagOptions<T>): IOptionFlag<T> => {
Expand Down
10 changes: 0 additions & 10 deletions src/handle_error.ts

This file was deleted.

55 changes: 28 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
# yarn lockfile v1


"@anycli/command@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.5.tgz#c7a6ee35344f1d854d5323e1f5a3f6b6da7e1b6d"
"@anycli/command@^1.2.5", "@anycli/command@^1.2.6":
version "1.2.8"
resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.8.tgz#7be61b9678cc2dfe2ea5fdbca521c16d0270eb18"
dependencies:
"@anycli/parser" "^3.2.4"

"@anycli/command@^1.2.6":
version "1.2.6"
resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.6.tgz#0e7d2d1856055c31ded61468c2c34c77260fd441"
dependencies:
"@anycli/parser" "^3.2.4"
"@anycli/config@^1.3.9":
version "1.3.9"
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-1.3.9.tgz#794b9f7dd6b2c8b23cfc448f8450206171a05655"

"@anycli/config@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-1.3.2.tgz#7d39e0c9f7d79a3fabde319bbbe08a4543411238"
"@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/parser@^3.2.4":
version "3.2.4"
resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.2.4.tgz#30297ac2fa225b37efaab5c0062bf189988b3ce8"
"@anycli/parser@^3.2.4", "@anycli/parser@^3.2.5":
version "3.2.5"
resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.2.5.tgz#d0e7ddb14945cb84377fa69095009ca6005e6b6d"

"@anycli/plugin-help@^0.6.3":
version "0.6.3"
Expand Down Expand Up @@ -66,9 +67,9 @@
version "0.0.3"
resolved "https://registry.yarnpkg.com/@anycli/screen/-/screen-0.0.3.tgz#f0afd970c3ed725702948a45a874ede1fdd9362e"

"@anycli/tslint@^0.2.5":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.5.tgz#63feeb981b11f36326e0cb745c62f51d55c2ed67"
"@anycli/tslint@^0.2.6":
version "0.2.6"
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.6.tgz#4251f4cb3744dc577309b4351d2c2e8b65072de2"
dependencies:
tslint "^5.9.1"
tslint-xo "^0.6.0"
Expand Down Expand Up @@ -236,8 +237,8 @@ clean-stack@^1.3.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31"

cli-ux@^3.3.16:
version "3.3.16"
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.16.tgz#b542f781c89b03467d5417b7510bbce96559c325"
version "3.3.17"
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.17.tgz#010ab03da355ebd05a62a776140cb76ee8857ca7"
dependencies:
"@anycli/screen" "^0.0.3"
"@heroku/linewrap" "^1.0.0"
Expand Down Expand Up @@ -273,8 +274,8 @@ [email protected]:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.6.0.tgz#9df7e52fb2a0cb0fb89058ee80c3104225f37e1d"

commander@^2.12.1:
version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
version "2.14.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.0.tgz#7b25325963e6aace20d3a9285b09379b0c2208b5"

[email protected]:
version "0.0.1"
Expand Down Expand Up @@ -547,8 +548,8 @@ lru-cache@^4.0.1:
yallist "^2.1.2"

make-error@^1.1.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.2.tgz#8762ffad2444dd8ff1f7c819629fa28e24fea1c4"
version "1.3.3"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.3.tgz#a97ae14ffd98b05f543e83ddc395e1b2b6e4cc6a"

minimatch@^3.0.4:
version "3.0.4"
Expand Down Expand Up @@ -805,11 +806,11 @@ tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"

tslint-consistent-codestyle@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/tslint-consistent-codestyle/-/tslint-consistent-codestyle-1.11.0.tgz#051493eeb3536a74e98d14b66f38028a785f8c2b"
version "1.11.1"
resolved "https://registry.yarnpkg.com/tslint-consistent-codestyle/-/tslint-consistent-codestyle-1.11.1.tgz#fa39ff5f5f8a25c537bd1e1f50de6190a2f4d70d"
dependencies:
tslib "^1.7.1"
tsutils "^2.12.2"
tsutils "^2.21.0"

tslint-eslint-rules@^4.1.1:
version "4.1.1"
Expand Down Expand Up @@ -854,7 +855,7 @@ tsutils@^1.4.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"

tsutils@^2.12.1, tsutils@^2.12.2:
tsutils@^2.12.1, tsutils@^2.21.0:
version "2.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.21.0.tgz#43466a2283a0abce64e2209bc732ad72f8a04fab"
dependencies:
Expand Down

0 comments on commit b9424dc

Please sign in to comment.