Comparing version 2.0.0-rc.1 to 2.0.0-rc.2
@@ -10,3 +10,3 @@ /// <reference types="node" /> | ||
} | ||
interface CommandFactory<Context extends DefaultContext> { | ||
export interface CommandFactory<Context extends DefaultContext> { | ||
new (): Command<Context>; | ||
@@ -30,5 +30,8 @@ compile(): core.Command<(cli: Cli<Context>, context: Context) => Command<Context>>; | ||
runExit(argv: string[], context: Context): Promise<void>; | ||
private usage; | ||
private error; | ||
usage(command: Command<Context> | null, { detailed }?: { | ||
detailed?: boolean; | ||
}): string; | ||
error(error: Error, { command }?: { | ||
command?: Command<Context> | null; | ||
}): string; | ||
} | ||
export {}; |
@@ -47,6 +47,7 @@ "use strict"; | ||
error.setBinaryName(this.name); | ||
return this.error(context, error, null); | ||
context.stderr.write(this.error(error)); | ||
return 1; | ||
} | ||
if (command.help) { | ||
context.stdout.write(this.usage(command, true)); | ||
context.stdout.write(this.usage(command, { detailed: true })); | ||
return 0; | ||
@@ -59,3 +60,4 @@ } | ||
catch (error) { | ||
return this.error(context, error, command); | ||
context.stderr.write(this.error(error, { command })); | ||
return 1; | ||
} | ||
@@ -69,3 +71,3 @@ if (typeof exitCode === `undefined`) | ||
} | ||
usage(command, detailed = false) { | ||
usage(command, { detailed = false } = {}) { | ||
let result = ``; | ||
@@ -88,7 +90,8 @@ if (command) { | ||
} | ||
error(context, error, command) { | ||
error(error, { command = null } = {}) { | ||
let result = ``; | ||
let name = error.name.replace(/([a-z])([A-Z])/g, `$1 $2`); | ||
if (name === `Error`) | ||
name = `Internal Error`; | ||
context.stdout.write(`${chalk_1.default.red.bold(name)}: ${error.message}\n`); | ||
result += `${chalk_1.default.red.bold(name)}: ${error.message}\n`; | ||
// @ts-ignore | ||
@@ -98,4 +101,4 @@ const meta = error.clipanion; | ||
if (meta.type === `usage`) { | ||
context.stdout.write(`\n`); | ||
context.stdout.write(this.usage(command)); | ||
result += `\n`; | ||
result += this.usage(command); | ||
} | ||
@@ -105,8 +108,8 @@ } | ||
if (error.stack) { | ||
context.stdout.write(`${error.stack.replace(/^.*\n/, ``)}\n`); | ||
result += `${error.stack.replace(/^.*\n/, ``)}\n`; | ||
} | ||
} | ||
return 1; | ||
return result; | ||
} | ||
} | ||
exports.Cli = Cli; |
@@ -1,2 +0,2 @@ | ||
export { Cli, DefaultContext } from './Cli'; | ||
export { Cli, CommandFactory, DefaultContext } from './Cli'; | ||
export { Command } from './Command'; |
{ | ||
"name": "clipanion", | ||
"version": "2.0.0-rc.1", | ||
"version": "2.0.0-rc.2", | ||
"main": "lib/advanced", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
49924
1191