bob-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Cli.d.ts +3 -0
- package/dist/Cli.js +8 -1
- package/dist/Command.d.ts +10 -4
- package/dist/Command.js +4 -5
- package/dist/CommandHelper.d.ts +4 -1
- package/dist/CommandHelper.js +41 -15
- package/dist/CommandRegistry.d.ts +0 -1
- package/dist/CommandRegistry.js +2 -19
- package/dist/ExceptionHandler.d.ts +4 -0
- package/dist/ExceptionHandler.js +14 -0
- package/dist/Parser.d.ts +16 -6
- package/dist/Parser.js +30 -7
- package/dist/errors/BadParameter.d.ts +11 -0
- package/dist/errors/BadParameter.js +36 -0
- package/dist/errors/BobError.d.ts +3 -0
- package/dist/errors/BobError.js +6 -0
- package/dist/errors/CommandNotFoundError.d.ts +7 -0
- package/dist/errors/CommandNotFoundError.js +57 -0
- package/dist/errors/MissingRequiredArgumentValue.d.ts +7 -0
- package/dist/errors/MissingRequiredArgumentValue.js +23 -0
- package/package.json +1 -1
package/dist/Cli.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { CommandRegistry } from "./CommandRegistry";
|
|
2
2
|
import { Command } from "./Command";
|
|
3
3
|
import HelpCommand from "./commands/HelpCommand";
|
|
4
|
+
import { ExceptionHandler } from "./ExceptionHandler";
|
|
4
5
|
export declare class Cli {
|
|
5
6
|
readonly commandRegistry: CommandRegistry;
|
|
7
|
+
private readonly exceptionHandler;
|
|
6
8
|
get CommandRegistryClass(): typeof CommandRegistry;
|
|
7
9
|
get HelpCommandClass(): typeof HelpCommand;
|
|
10
|
+
get ExceptionHandlerClass(): typeof ExceptionHandler;
|
|
8
11
|
constructor();
|
|
9
12
|
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
10
13
|
registerCommand(command: Command): void;
|
package/dist/Cli.js
CHANGED
|
@@ -6,16 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Cli = void 0;
|
|
7
7
|
const CommandRegistry_1 = require("./CommandRegistry");
|
|
8
8
|
const HelpCommand_1 = __importDefault(require("./commands/HelpCommand"));
|
|
9
|
+
const ExceptionHandler_1 = require("./ExceptionHandler");
|
|
9
10
|
class Cli {
|
|
10
11
|
commandRegistry;
|
|
12
|
+
exceptionHandler;
|
|
11
13
|
get CommandRegistryClass() {
|
|
12
14
|
return CommandRegistry_1.CommandRegistry;
|
|
13
15
|
}
|
|
14
16
|
get HelpCommandClass() {
|
|
15
17
|
return HelpCommand_1.default;
|
|
16
18
|
}
|
|
19
|
+
get ExceptionHandlerClass() {
|
|
20
|
+
return ExceptionHandler_1.ExceptionHandler;
|
|
21
|
+
}
|
|
17
22
|
constructor() {
|
|
18
23
|
this.commandRegistry = new this.CommandRegistryClass();
|
|
24
|
+
this.exceptionHandler = new this.ExceptionHandlerClass();
|
|
19
25
|
this.registerCommand(new this.HelpCommandClass(this.commandRegistry));
|
|
20
26
|
}
|
|
21
27
|
async loadCommandsPath(commandsPath) {
|
|
@@ -25,7 +31,8 @@ class Cli {
|
|
|
25
31
|
this.commandRegistry.registerCommand(command);
|
|
26
32
|
}
|
|
27
33
|
async runCommand(command, ...args) {
|
|
28
|
-
return await this.commandRegistry.runCommand(command, ...args)
|
|
34
|
+
return await this.commandRegistry.runCommand(command, ...args)
|
|
35
|
+
.catch(this.exceptionHandler.handle);
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
exports.Cli = Cli;
|
package/dist/Command.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { CommandHelper } from "./CommandHelper";
|
|
2
|
+
import { Parser } from "./Parser";
|
|
3
|
+
export type CommandExample = {
|
|
4
|
+
description: string;
|
|
5
|
+
command: string;
|
|
6
|
+
};
|
|
2
7
|
export declare abstract class Command extends CommandHelper {
|
|
3
8
|
abstract signature: string;
|
|
4
9
|
abstract description: string;
|
|
5
|
-
|
|
10
|
+
protected helperDefinitions: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
protected commandsExamples: CommandExample[];
|
|
14
|
+
protected parser: Parser;
|
|
6
15
|
get command(): string;
|
|
7
16
|
protected abstract handle(): Promise<void | number>;
|
|
8
17
|
run(...args: any[]): Promise<number>;
|
|
9
18
|
protected option(key: string, defaultValue?: any): string | null;
|
|
10
19
|
protected argument(key: string, defaultValue?: any): string | null;
|
|
11
|
-
signatures(): {
|
|
12
|
-
[argument: string]: import("./Parser").ParamSignature;
|
|
13
|
-
};
|
|
14
20
|
}
|
package/dist/Command.js
CHANGED
|
@@ -4,14 +4,16 @@ exports.Command = void 0;
|
|
|
4
4
|
const CommandHelper_1 = require("./CommandHelper");
|
|
5
5
|
const Parser_1 = require("./Parser");
|
|
6
6
|
class Command extends CommandHelper_1.CommandHelper {
|
|
7
|
+
helperDefinitions = {};
|
|
8
|
+
commandsExamples = [];
|
|
7
9
|
parser;
|
|
8
10
|
get command() {
|
|
9
11
|
return this.signature.split(' ')[0];
|
|
10
12
|
}
|
|
11
13
|
async run(...args) {
|
|
12
|
-
this.parser = new Parser_1.Parser(this.signature, ...args);
|
|
14
|
+
this.parser = new Parser_1.Parser(this.signature, this.helperDefinitions, ...args);
|
|
13
15
|
if (args.includes('--help') || args.includes('-h')) {
|
|
14
|
-
return this.help();
|
|
16
|
+
return this.help.bind(this)();
|
|
15
17
|
}
|
|
16
18
|
this.parser.validate();
|
|
17
19
|
return (await this.handle()) ?? 0;
|
|
@@ -22,8 +24,5 @@ class Command extends CommandHelper_1.CommandHelper {
|
|
|
22
24
|
argument(key, defaultValue) {
|
|
23
25
|
return this.parser.argument(key) ?? defaultValue;
|
|
24
26
|
}
|
|
25
|
-
signatures() {
|
|
26
|
-
return this.parser.signatures();
|
|
27
|
-
}
|
|
28
27
|
}
|
|
29
28
|
exports.Command = Command;
|
package/dist/CommandHelper.d.ts
CHANGED
package/dist/CommandHelper.js
CHANGED
|
@@ -8,33 +8,59 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
9
|
const string_1 = require("./lib/string");
|
|
10
10
|
class CommandHelper {
|
|
11
|
+
get defaultOptions() {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
name: 'help',
|
|
15
|
+
optional: true,
|
|
16
|
+
help: (0, chalk_1.default) `Display help for the given command. When no command is given display help for the {green list} command`,
|
|
17
|
+
alias: ['h']
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
}
|
|
11
21
|
help() {
|
|
12
|
-
const command = this;
|
|
13
22
|
const log = console.log;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
const availableArguments = Object.values(this.parser.argumentsSignatures());
|
|
24
|
+
const availableOptions = [...Object.values(this.parser.optionsSignatures()), ...this.defaultOptions]
|
|
25
|
+
.map((signature) => ({
|
|
26
|
+
...signature,
|
|
27
|
+
optionWithAlias: `--${signature.name}${signature.alias?.map(a => `, -${a}`).join('') ?? ''}`
|
|
28
|
+
}));
|
|
29
|
+
const requiredArguments = availableArguments.filter((signature) => !signature.optional);
|
|
18
30
|
log((0, chalk_1.default) `{yellow Description}:`);
|
|
19
|
-
log((0, chalk_1.default) ` ${
|
|
31
|
+
log((0, chalk_1.default) ` ${this.description}\n`);
|
|
20
32
|
log((0, chalk_1.default) `{yellow Usage}:`);
|
|
21
|
-
log((0, chalk_1.default) ` ${
|
|
22
|
-
const maxOptionLength = (0, lodash_1.max)(availableOptions.map((
|
|
23
|
-
const maxArgumentLength = (0, lodash_1.max)(availableArguments.map((
|
|
33
|
+
log((0, chalk_1.default) ` ${this.command} ${requiredArguments.length > 0 ? requiredArguments.map((signature) => `<${signature.name}>`).join(' ') : '\b'} [options]`);
|
|
34
|
+
const maxOptionLength = (0, lodash_1.max)(availableOptions.map((signature) => signature.optionWithAlias.length)) ?? 0;
|
|
35
|
+
const maxArgumentLength = (0, lodash_1.max)(availableArguments.map((arg) => arg.name.length)) ?? 0;
|
|
24
36
|
const maxLength = maxArgumentLength > maxOptionLength ? maxArgumentLength : maxOptionLength;
|
|
25
37
|
if (availableArguments.length > 0) {
|
|
26
38
|
log((0, chalk_1.default) `{yellow Arguments}:`);
|
|
27
|
-
for (const
|
|
28
|
-
const spaces = (0, string_1.generateSpace)(maxLength -
|
|
29
|
-
log((0, chalk_1.default) ` {green ${
|
|
39
|
+
for (const signature of availableArguments) {
|
|
40
|
+
const spaces = (0, string_1.generateSpace)(maxLength - signature.name.length);
|
|
41
|
+
log((0, chalk_1.default) ` {green ${signature.name}} ${spaces} ${signature.help ?? '\b'} ${signature.optional ? (0, chalk_1.default) `{gray (optional)}` : ''}`);
|
|
30
42
|
}
|
|
31
43
|
log((0, chalk_1.default) ``);
|
|
32
44
|
}
|
|
33
45
|
if (availableOptions.length > 0) {
|
|
34
46
|
log((0, chalk_1.default) `{yellow Options}:`);
|
|
35
|
-
for (const
|
|
36
|
-
const spaces = (0, string_1.generateSpace)(maxLength -
|
|
37
|
-
log((0, chalk_1.default) ` {green ${
|
|
47
|
+
for (const signature of availableOptions) {
|
|
48
|
+
const spaces = (0, string_1.generateSpace)(maxLength - signature.optionWithAlias.length);
|
|
49
|
+
log((0, chalk_1.default) ` {green ${signature.optionWithAlias}} ${spaces} ${signature.help ?? '\b'} `);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (this.commandsExamples.length > 0) {
|
|
53
|
+
log((0, chalk_1.default) `\n{yellow Examples}:`);
|
|
54
|
+
let binaryName = process.argv[0].split('/').pop();
|
|
55
|
+
if (binaryName === 'node') {
|
|
56
|
+
binaryName += ' ' + process.argv[1].split('/').pop();
|
|
57
|
+
}
|
|
58
|
+
for (const [index, example] of this.commandsExamples.entries()) {
|
|
59
|
+
if (index > 0) {
|
|
60
|
+
log('');
|
|
61
|
+
}
|
|
62
|
+
log(` ${example.description}\n`);
|
|
63
|
+
log((0, chalk_1.default) ` {green ${binaryName} ${example.command}}`);
|
|
38
64
|
}
|
|
39
65
|
}
|
|
40
66
|
return -1;
|
package/dist/CommandRegistry.js
CHANGED
|
@@ -29,8 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.CommandRegistry = void 0;
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
31
|
const fs = __importStar(require("node:fs"));
|
|
32
|
-
const
|
|
33
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
32
|
+
const CommandNotFoundError_1 = require("./errors/CommandNotFoundError");
|
|
34
33
|
class CommandRegistry {
|
|
35
34
|
commands = {};
|
|
36
35
|
get commandSuffix() {
|
|
@@ -75,7 +74,7 @@ class CommandRegistry {
|
|
|
75
74
|
async runCommand(command, ...args) {
|
|
76
75
|
const commandToRun = this.commands[command];
|
|
77
76
|
if (!this.commands[command]) {
|
|
78
|
-
|
|
77
|
+
throw new CommandNotFoundError_1.CommandNotFoundError(command, this.getAvailableCommands());
|
|
79
78
|
}
|
|
80
79
|
return await commandToRun.run(...args);
|
|
81
80
|
}
|
|
@@ -94,21 +93,5 @@ class CommandRegistry {
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
|
-
commandNotFound(command) {
|
|
98
|
-
const log = console.log;
|
|
99
|
-
const similarCommands = this.getCommands().filter(cmd => cmd.command //
|
|
100
|
-
.split(':')
|
|
101
|
-
.filter(part => SS.compareTwoStrings(part, command) > 0.3).length);
|
|
102
|
-
if (similarCommands.length) {
|
|
103
|
-
log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${command}" is not defined, Did you mean one of these?`);
|
|
104
|
-
for (const cmd of similarCommands) {
|
|
105
|
-
log((0, chalk_1.default) ` {gray ⇂ ${cmd.command}}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${command}" is not defined.`);
|
|
110
|
-
}
|
|
111
|
-
return 1;
|
|
112
|
-
}
|
|
113
96
|
}
|
|
114
97
|
exports.CommandRegistry = CommandRegistry;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExceptionHandler = void 0;
|
|
4
|
+
const BobError_1 = require("./errors/BobError");
|
|
5
|
+
class ExceptionHandler {
|
|
6
|
+
handle(err) {
|
|
7
|
+
if (err instanceof BobError_1.BobError) {
|
|
8
|
+
err.pretty();
|
|
9
|
+
return -1;
|
|
10
|
+
}
|
|
11
|
+
throw err;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ExceptionHandler = ExceptionHandler;
|
package/dist/Parser.d.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ArgSignature = {
|
|
2
2
|
name: string;
|
|
3
3
|
optional: boolean;
|
|
4
|
-
alias?: string;
|
|
4
|
+
alias?: string[];
|
|
5
5
|
help?: string;
|
|
6
6
|
defaultValue?: string | boolean | null;
|
|
7
|
-
isOption
|
|
7
|
+
isOption?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export declare class Parser {
|
|
10
|
+
protected readonly signature: string;
|
|
11
|
+
protected readonly helperDefinitions: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
10
14
|
command: string;
|
|
11
15
|
private arguments;
|
|
12
16
|
private options;
|
|
13
17
|
private argumentsSignature;
|
|
18
|
+
private optionsSignature;
|
|
14
19
|
option(name: string): any;
|
|
15
20
|
argument(name: string): any;
|
|
16
|
-
|
|
17
|
-
[argument: string]:
|
|
21
|
+
argumentsSignatures(): {
|
|
22
|
+
[argument: string]: ArgSignature;
|
|
23
|
+
};
|
|
24
|
+
optionsSignatures(): {
|
|
25
|
+
[option: string]: ArgSignature;
|
|
18
26
|
};
|
|
19
|
-
constructor(signature: string,
|
|
27
|
+
constructor(signature: string, helperDefinitions: {
|
|
28
|
+
[key: string]: string;
|
|
29
|
+
}, ...args: any[]);
|
|
20
30
|
private parseSignature;
|
|
21
31
|
private parseParamSignature;
|
|
22
32
|
validate(): void;
|
package/dist/Parser.js
CHANGED
|
@@ -5,21 +5,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Parser = void 0;
|
|
7
7
|
const minimist_1 = __importDefault(require("minimist"));
|
|
8
|
+
const MissingRequiredArgumentValue_1 = require("./errors/MissingRequiredArgumentValue");
|
|
8
9
|
class Parser {
|
|
10
|
+
signature;
|
|
11
|
+
helperDefinitions;
|
|
9
12
|
command;
|
|
10
13
|
arguments = {};
|
|
11
14
|
options = {};
|
|
12
15
|
argumentsSignature = {};
|
|
16
|
+
optionsSignature = {};
|
|
13
17
|
option(name) {
|
|
14
18
|
return this.options[name];
|
|
15
19
|
}
|
|
16
20
|
argument(name) {
|
|
17
21
|
return this.arguments[name];
|
|
18
22
|
}
|
|
19
|
-
|
|
23
|
+
argumentsSignatures() {
|
|
20
24
|
return this.argumentsSignature;
|
|
21
25
|
}
|
|
22
|
-
|
|
26
|
+
optionsSignatures() {
|
|
27
|
+
return this.optionsSignature;
|
|
28
|
+
}
|
|
29
|
+
constructor(signature, helperDefinitions, ...args) {
|
|
30
|
+
this.signature = signature;
|
|
31
|
+
this.helperDefinitions = helperDefinitions;
|
|
23
32
|
const [command, ...params] = signature.split(/\{(.*?)\}/g).map(param => param.trim()).filter(Boolean);
|
|
24
33
|
const { _: paramValues, ...optionValues } = (0, minimist_1.default)(args);
|
|
25
34
|
this.command = command;
|
|
@@ -31,12 +40,19 @@ class Parser {
|
|
|
31
40
|
if (param.isOption) {
|
|
32
41
|
const optionValue = optionValues[param.name];
|
|
33
42
|
this.options[param.name] = optionValue ?? param.defaultValue ?? null;
|
|
43
|
+
this.optionsSignature[param.name] = param;
|
|
44
|
+
for (const alias of param.alias ?? []) {
|
|
45
|
+
if (optionValues[alias]) {
|
|
46
|
+
this.options[param.name] = optionValues[alias];
|
|
47
|
+
this.optionsSignature[param.name] = param;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
34
50
|
}
|
|
35
51
|
else {
|
|
36
52
|
const paramValue = paramValues.shift();
|
|
37
53
|
this.arguments[param.name] = paramValue ?? param.defaultValue ?? null;
|
|
54
|
+
this.argumentsSignature[param.name] = param;
|
|
38
55
|
}
|
|
39
|
-
this.argumentsSignature[param.name] = param;
|
|
40
56
|
}
|
|
41
57
|
}
|
|
42
58
|
parseParamSignature(argument) {
|
|
@@ -78,19 +94,26 @@ class Parser {
|
|
|
78
94
|
arg.defaultValue = false;
|
|
79
95
|
}
|
|
80
96
|
}
|
|
97
|
+
if (arg.name.includes('|')) {
|
|
98
|
+
const [name, ...alias] = arg.name.split('|');
|
|
99
|
+
arg.name = name.trim();
|
|
100
|
+
arg.alias = alias.map(a => a.trim());
|
|
101
|
+
}
|
|
81
102
|
if (arg.name.startsWith('--')) {
|
|
82
103
|
arg.isOption = true;
|
|
83
104
|
arg.name = arg.name.slice(2);
|
|
84
105
|
}
|
|
106
|
+
if (this.helperDefinitions[arg.name]) {
|
|
107
|
+
arg.help = this.helperDefinitions[arg.name];
|
|
108
|
+
}
|
|
85
109
|
return arg;
|
|
86
110
|
}
|
|
87
111
|
validate() {
|
|
88
112
|
// validate arguments
|
|
89
113
|
for (const [argument, value] of Object.entries(this.arguments)) {
|
|
90
|
-
const
|
|
91
|
-
if (!value && !
|
|
92
|
-
|
|
93
|
-
throw new Error(`Argument ${argument} is required. (help: ${argumentHelp})`);
|
|
114
|
+
const argSignature = this.argumentsSignature[argument];
|
|
115
|
+
if (!value && !argSignature.optional) {
|
|
116
|
+
throw new MissingRequiredArgumentValue_1.MissingRequiredArgumentValue(argSignature);
|
|
94
117
|
}
|
|
95
118
|
}
|
|
96
119
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BobError } from "./BobError";
|
|
2
|
+
export type BadParameterProps = {
|
|
3
|
+
param: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
reason?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class BadParameter extends BobError {
|
|
8
|
+
readonly param: BadParameterProps;
|
|
9
|
+
constructor(param: BadParameterProps);
|
|
10
|
+
pretty(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BadParameter = void 0;
|
|
7
|
+
const BobError_1 = require("./BobError");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
class BadParameter extends BobError_1.BobError {
|
|
10
|
+
param;
|
|
11
|
+
constructor(param) {
|
|
12
|
+
let message = `Argument "${param.param}" value is invalid.`;
|
|
13
|
+
if (param.reason) {
|
|
14
|
+
message += ` Reason: ${param.reason}`;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
message += ` Value: "${param.value}"`;
|
|
18
|
+
}
|
|
19
|
+
super(message);
|
|
20
|
+
this.param = param;
|
|
21
|
+
}
|
|
22
|
+
pretty() {
|
|
23
|
+
const log = console.log;
|
|
24
|
+
log((0, chalk_1.default) ` {white.bgRed ERROR } Argument "${this.param.param}" value is invalid. `);
|
|
25
|
+
if (this.param.value || this.param.reason) {
|
|
26
|
+
log('');
|
|
27
|
+
}
|
|
28
|
+
if (this.param.value) {
|
|
29
|
+
log((0, chalk_1.default) ` {blue Value}: ${this.param.value}`);
|
|
30
|
+
}
|
|
31
|
+
if (this.param.reason) {
|
|
32
|
+
log((0, chalk_1.default) ` {yellow Reason}: ${this.param.reason}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BadParameter = BadParameter;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.CommandNotFoundError = void 0;
|
|
30
|
+
const BobError_1 = require("./BobError");
|
|
31
|
+
const SS = __importStar(require("string-similarity"));
|
|
32
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
class CommandNotFoundError extends BobError_1.BobError {
|
|
34
|
+
command;
|
|
35
|
+
availableCommands;
|
|
36
|
+
constructor(command, availableCommands) {
|
|
37
|
+
super(`Command "${command}" not found.`);
|
|
38
|
+
this.command = command;
|
|
39
|
+
this.availableCommands = availableCommands;
|
|
40
|
+
}
|
|
41
|
+
pretty() {
|
|
42
|
+
const log = console.log;
|
|
43
|
+
const similarCommands = this.availableCommands.filter(cmd => cmd //
|
|
44
|
+
.split(':')
|
|
45
|
+
.filter(part => SS.compareTwoStrings(part, this.command) > 0.3).length);
|
|
46
|
+
if (similarCommands.length) {
|
|
47
|
+
log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${this.command}" is not defined, Did you mean one of these?`);
|
|
48
|
+
for (const cmd of similarCommands) {
|
|
49
|
+
log((0, chalk_1.default) ` {gray ⇂ ${this.command}}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${this.command}" is not defined.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CommandNotFoundError = CommandNotFoundError;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MissingRequiredArgumentValue = void 0;
|
|
7
|
+
const BobError_1 = require("./BobError");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
class MissingRequiredArgumentValue extends BobError_1.BobError {
|
|
10
|
+
paramSignature;
|
|
11
|
+
constructor(paramSignature) {
|
|
12
|
+
super(`Argument "${paramSignature.name}" is required.`);
|
|
13
|
+
this.paramSignature = paramSignature;
|
|
14
|
+
}
|
|
15
|
+
pretty() {
|
|
16
|
+
const log = console.log;
|
|
17
|
+
log((0, chalk_1.default) ` {white.bgRed ERROR } Argument "${this.paramSignature.name}" is required.`);
|
|
18
|
+
if (this.paramSignature.help) {
|
|
19
|
+
log((0, chalk_1.default) `\n {yellow Help}: ${this.paramSignature.help}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.MissingRequiredArgumentValue = MissingRequiredArgumentValue;
|