@anycli/command
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -0,1 +1,9 @@ | ||
<a name="1.2.5"></a> | ||
## [1.2.5](https://github.com/anycli/command/compare/26895f76a879a002cf01319aba3779ba4cad8ae9...v1.2.5) (2018-02-05) | ||
### Bug Fixes | ||
* reduce dependencies ([7b0acc6](https://github.com/anycli/command/commit/7b0acc6)) | ||
<a name="1.2.4"></a> | ||
@@ -2,0 +10,0 @@ ## [1.2.4](https://github.com/anycli/command/compare/a002c7c2e3f54a0a0bd37b4844ceea5d815d69f6...v1.2.4) (2018-02-03) |
@@ -38,2 +38,4 @@ import * as Config from '@anycli/config'; | ||
_run(): Promise<void>; | ||
exit(code?: number): void; | ||
log(s?: string | undefined): void; | ||
/** | ||
@@ -47,3 +49,3 @@ * actual command run code goes here | ||
}>(options?: Parser.Input<F>, argv?: string[]): Parser.Output<F, A>; | ||
protected catch(err: Error): Promise<void>; | ||
protected catch(err: any): Promise<void>; | ||
protected finally(_: Error | undefined): Promise<void>; | ||
@@ -50,0 +52,0 @@ protected _help(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable no-implicit-dependencies | ||
const pjson = require('../package.json'); | ||
const Config = require("@anycli/config"); | ||
const Parser = require("@anycli/parser"); | ||
const cli_ux_1 = require("cli-ux"); | ||
const _ = require("lodash"); | ||
const exit_1 = require("./exit"); | ||
const flags = require("./flags"); | ||
const util_1 = require("./util"); | ||
class Command { | ||
@@ -14,3 +14,8 @@ constructor(argv, options) { | ||
this.config = Config.load(options || module.parent && module.parent.parent && module.parent.parent.filename || __dirname); | ||
this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin); | ||
try { | ||
this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin); | ||
} | ||
catch (_a) { | ||
this.debug = () => { }; | ||
} | ||
} | ||
@@ -34,9 +39,15 @@ get ctor() { | ||
} | ||
exit(code) { throw new exit_1.ExitError(code || 0); } | ||
log(s) { | ||
process.stdout.write((s || '') + '\n'); | ||
} | ||
async init() { | ||
this.debug('init version: %s argv: %o', this.ctor._base, this.argv); | ||
cli_ux_1.default.config.context.command = _.compact([this.id, ...this.argv]).join(' '); | ||
cli_ux_1.default.config.context.version = this.config.userAgent; | ||
if (this.config.debug) | ||
cli_ux_1.default.config.debug = true; | ||
cli_ux_1.default.config.errlog = this.config.errlog; | ||
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: util_1.compact([this.id, ...this.argv]).join(' '), | ||
version: this.config.userAgent, | ||
}; | ||
global['http-call'] = global['http-call'] || {}; | ||
@@ -51,6 +62,9 @@ global['http-call'].userAgent = this.config.userAgent; | ||
options = this.constructor; | ||
return Parser.parse(argv, Object.assign({ context: this }, options)); | ||
return require('@anycli/parser').parse(argv, Object.assign({ context: this }, options)); | ||
} | ||
async catch(err) { | ||
if (err.message.match(/Unexpected arguments?: (-h|--help)(,|\n)/)) { | ||
if (err && err['cli-ux'] && err['cli-ux'].exit !== undefined) { | ||
process.exitCode = err['cli-ux'].exit; | ||
} | ||
else if (err.message.match(/Unexpected arguments?: (-h|--help)(,|\n)/)) { | ||
this._help(); | ||
@@ -62,11 +76,9 @@ } | ||
else | ||
cli_ux_1.default.error(err); | ||
throw err; | ||
} | ||
async finally(_) { | ||
try { | ||
await cli_ux_1.default.done(); | ||
await require('cli-ux').done(); | ||
} | ||
catch (err) { | ||
cli_ux_1.default.warn(err); | ||
} | ||
catch (_a) { } | ||
} | ||
@@ -77,3 +89,3 @@ _help() { | ||
help.showHelp(this.argv); | ||
cli_ux_1.default.exit(0); | ||
this.exit(0); | ||
} | ||
@@ -92,4 +104,4 @@ _helpOverride() { | ||
_version() { | ||
cli_ux_1.default.info(this.config.userAgent); | ||
cli_ux_1.default.exit(0); | ||
this.log(this.config.userAgent); | ||
this.exit(0); | ||
} | ||
@@ -96,0 +108,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Parser = require("@anycli/parser"); | ||
const cli_ux_1 = require("cli-ux"); | ||
function build(defaults) { | ||
@@ -29,4 +28,4 @@ return Parser.flags.build(defaults); | ||
description: 'show CLI version' }, opts, { parse: (_, cmd) => { | ||
cli_ux_1.default.info(cmd.config.userAgent); | ||
cli_ux_1.default.exit(0); | ||
cmd.log(cmd.config.userAgent); | ||
cmd.exit(0); | ||
} })); | ||
@@ -40,4 +39,5 @@ }; | ||
const help = new HHelp(cmd.config); | ||
cli_ux_1.default.info(help); | ||
help.showHelp(cmd.argv); | ||
cmd.exit(0); | ||
} })); | ||
}; |
@@ -1,7 +0,5 @@ | ||
import * as Config from '@anycli/config'; | ||
import Command from './command'; | ||
import * as flags from './flags'; | ||
export { parse } from '@anycli/parser'; | ||
export { run, Main } from './main'; | ||
export default Command; | ||
export { Config, Command, flags }; | ||
export { Command, flags }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Config = require("@anycli/config"); | ||
exports.Config = Config; | ||
const command_1 = require("./command"); | ||
@@ -9,4 +7,2 @@ exports.Command = command_1.default; | ||
exports.flags = flags; | ||
var parser_1 = require("@anycli/parser"); | ||
exports.parse = parser_1.parse; | ||
var main_1 = require("./main"); | ||
@@ -13,0 +9,0 @@ exports.run = main_1.run; |
{ | ||
"name": "@anycli/command", | ||
"description": "anycli base command", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -16,12 +16,7 @@ "bugs": "https://github.com/anycli/command/issues", | ||
"dependencies": { | ||
"@anycli/parser": "^3.2.2", | ||
"cli-ux": "^3.3.13", | ||
"debug": "^3.1.0", | ||
"fs-extra": "^5.0.0", | ||
"load-json-file": "^4.0.0", | ||
"lodash": "^4.17.4" | ||
"@anycli/parser": "^3.2.4" | ||
}, | ||
"devDependencies": { | ||
"@anycli/config": "^1.1.2", | ||
"@anycli/plugin-help": "^0.6.0", | ||
"@anycli/config": "^1.1.6", | ||
"@anycli/plugin-help": "^0.6.1", | ||
"@anycli/plugin-not-found": "^0.1.15", | ||
@@ -31,15 +26,8 @@ "@anycli/plugin-plugins": "^0.2.11", | ||
"@types/chai": "^4.1.2", | ||
"@types/fs-extra": "^5.0.0", | ||
"@types/load-json-file": "^2.0.7", | ||
"@types/lodash": "^4.14.100", | ||
"@types/mocha": "^2.2.48", | ||
"@types/nock": "^9.1.2", | ||
"@types/node": "^9.4.0", | ||
"@types/node-notifier": "^0.0.28", | ||
"@types/read-pkg": "^3.0.0", | ||
"chai": "^4.1.2", | ||
"concurrently": "^3.5.1", | ||
"eslint": "^4.17.0", | ||
"eslint-config-anycli": "^1.3.2", | ||
"fancy-test": "^0.6.10", | ||
"fancy-test": "^1.0.1", | ||
"http-call": "^5.0.2", | ||
@@ -66,3 +54,3 @@ "mocha": "^5.0.0", | ||
"build": "rm -rf lib && tsc", | ||
"lint": "concurrently -p command \"eslint .\" \"tsc -p test --noEmit\" \"tslint -p test\"", | ||
"lint": "concurrently -p command \"tsc -p test --noEmit\" \"tslint -p test\"", | ||
"posttest": "yarn run lint", | ||
@@ -69,0 +57,0 @@ "prepublishOnly": "yarn run build", |
34445
1
17
15
376
- Removedcli-ux@^3.3.13
- Removeddebug@^3.1.0
- Removedfs-extra@^5.0.0
- Removedload-json-file@^4.0.0
- Removedlodash@^4.17.4
- Removed@oclif/linewrap@1.0.0(transitive)
- Removed@oclif/screen@1.0.4(transitive)
- Removedansi-escapes@4.3.2(transitive)
- Removedansi-regex@3.0.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedansicolors@0.3.2(transitive)
- Removedcardinal@2.1.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedclean-stack@1.3.0(transitive)
- Removedcli-ux@3.5.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@3.2.7(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesprima@4.0.1(transitive)
- Removedextract-stack@1.0.0(transitive)
- Removedfs-extra@5.0.06.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedms@2.1.3(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpassword-prompt@1.1.3(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpify@3.0.0(transitive)
- Removedredeyed@2.1.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedstrip-ansi@4.0.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtype-fest@0.21.3(transitive)
- Removeduniversalify@0.1.2(transitive)
- Removedwhich@2.0.2(transitive)
Updated@anycli/parser@^3.2.4