cli-engine-command
Advanced tools
Comparing version 9.0.0-ts.2 to 9.0.0-ts.3
@@ -21,8 +21,9 @@ /// <reference types="chalk" /> | ||
aliases: string[]; | ||
strict: boolean; | ||
variableArgs: boolean; | ||
Flags: InputFlags; | ||
Args: InputArgs; | ||
_version: any; | ||
plugin?: Plugin; | ||
parse: { | ||
args?: InputArgs; | ||
flags: InputFlags; | ||
strict?: boolean; | ||
}; | ||
readonly id: string; | ||
@@ -34,3 +35,3 @@ static mock<T extends Command>(...argv: string[]): Promise<IMockOutput<T>>; | ||
cli: CLI; | ||
flags: OutputFlags<this['Flags']>; | ||
flags: OutputFlags<this['parse']['flags']>; | ||
argv: string[]; | ||
@@ -40,7 +41,8 @@ args: OutputArgs; | ||
constructor(config?: ConfigOptions); | ||
readonly out: CLI; | ||
_run(): Promise<void>; | ||
init(): Promise<void>; | ||
run(): Promise<void>; | ||
done(): Promise<void>; | ||
buildHelp(): string; | ||
buildHelpLine(): [string, string | undefined]; | ||
} |
@@ -15,3 +15,2 @@ "use strict"; | ||
const help_1 = require("./help"); | ||
const util_1 = require("util"); | ||
const pjson = require('../package.json'); | ||
@@ -23,17 +22,5 @@ const debug = require('debug')('cli-engine-command'); | ||
this.aliases = []; | ||
this.strict = true; | ||
this.variableArgs = false; | ||
this.Flags = {}; | ||
this.Args = []; | ||
this._version = pjson.version; | ||
this.parse = { flags: {} }; | ||
this.config = cli_engine_config_1.buildConfig(config); | ||
this.color = require('chalk'); | ||
const { CLI } = require('cli-ux'); | ||
this.cli = new CLI({ debug: this.config.debug, mock: this.config.mock, errlog: this.config.errlog }); | ||
this.http = http_call_1.HTTP.defaults({ | ||
headers: { | ||
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config | ||
.arch}) node-${process.version}`, | ||
}, | ||
}); | ||
} | ||
@@ -68,33 +55,36 @@ get id() { | ||
const cmd = new this(config); | ||
yield cmd._run(); | ||
return cmd; | ||
}); | ||
} | ||
_run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
debug('initializing %s version: %s', cmd.id, cmd._version); | ||
debug('argv: %o', cmd.config.argv); | ||
yield cmd.init(); | ||
debug('initializing %s version: %s', this.id, this._version); | ||
debug('argv: %o', this.config.argv); | ||
yield this.init(); | ||
debug('run'); | ||
yield cmd.run(); | ||
yield this.run(); | ||
debug('done'); | ||
yield cmd.cli.done(); | ||
yield this.cli.done(); | ||
} | ||
catch (err) { | ||
cmd.cli.error(err); | ||
this.cli.error(err); | ||
} | ||
return cmd; | ||
}); | ||
} | ||
get out() { | ||
util_1.deprecate(() => { }, 'this.out is deprecated, use this.cli'); | ||
return this.cli; | ||
} | ||
init() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cli.handleUnhandleds(); | ||
if (this.variableArgs) { | ||
util_1.deprecate(() => { }, 'variableArgs is deprecated. Use strict = true instead.'); | ||
} | ||
const { argv, flags, args } = yield cli_flags_1.parse({ | ||
flags: this.Flags, | ||
args: this.Args, | ||
strict: this.strict !== false && !this.variableArgs, | ||
argv: this.config.argv.slice(2), | ||
this.color = require('chalk'); | ||
const { CLI } = require('cli-ux'); | ||
this.cli = new CLI({ debug: this.config.debug, mock: this.config.mock, errlog: this.config.errlog }); | ||
this.http = http_call_1.HTTP.defaults({ | ||
headers: { | ||
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config | ||
.arch}) node-${process.version}`, | ||
}, | ||
}); | ||
if (!this.config.mock) | ||
this.cli.handleUnhandleds(); | ||
const { argv, flags, args } = yield cli_flags_1.parse(Object.assign({}, this.parse, { argv: this.config.argv.slice(2) })); | ||
this.flags = flags; | ||
@@ -108,2 +98,7 @@ this.argv = argv; | ||
} | ||
done() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.cli.done(); | ||
}); | ||
} | ||
buildHelp() { | ||
@@ -110,0 +105,0 @@ let help = new help_1.Help(this.config); |
@@ -9,5 +9,5 @@ "use strict"; | ||
let cmd = command.id; | ||
if (!command.Args) | ||
if (!command.parse.args) | ||
return cmd.trim(); | ||
let args = command.Args.map(renderArg); | ||
let args = command.parse.args.map(renderArg); | ||
return `${cmd} ${args.join(' ')}`.trim(); | ||
@@ -27,4 +27,4 @@ } | ||
command(cmd) { | ||
let flags = Object.entries(cmd.Flags || {}).filter(([, flag]) => !flag.hidden); | ||
let args = (cmd.Args || []).filter(a => !a.hidden); | ||
let flags = Object.entries(cmd.parse.flags || {}).filter(([, flag]) => !flag.hidden); | ||
let args = (cmd.parse.args || []).filter(a => !a.hidden); | ||
let hasFlags = flags.length ? ` ${chalk.blue('[flags]')}` : ''; | ||
@@ -31,0 +31,0 @@ let usage = `${chalk.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`; |
{ | ||
"name": "cli-engine-command", | ||
"description": "base CLI command for cli-engine", | ||
"version": "9.0.0-ts.2", | ||
"version": "9.0.0-ts.3", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -25,3 +25,3 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues", | ||
"@types/node": "^8.0.28", | ||
"cli-engine-config": "^4.0.1-ts.5", | ||
"cli-engine-config": "^4.0.1-ts.7", | ||
"del-cli": "^1.1.0", | ||
@@ -28,0 +28,0 @@ "husky": "^0.14.3", |
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
11195
258