bob-core 0.4.0 → 0.5.1
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 -2
- package/dist/Cli.js +4 -2
- package/dist/Command.d.ts +3 -2
- package/dist/Command.js +7 -2
- package/dist/CommandHelper.d.ts +1 -1
- package/dist/CommandRegistry.d.ts +1 -1
- package/dist/CommandRegistry.js +2 -2
- package/package.json +1 -1
package/dist/Cli.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { CommandRegistry } from "./CommandRegistry";
|
|
|
2
2
|
import { Command } from "./Command";
|
|
3
3
|
import HelpCommand from "./commands/HelpCommand";
|
|
4
4
|
import { ExceptionHandler } from "./ExceptionHandler";
|
|
5
|
-
export declare class Cli {
|
|
5
|
+
export declare class Cli<C> {
|
|
6
6
|
readonly commandRegistry: CommandRegistry;
|
|
7
7
|
private readonly exceptionHandler;
|
|
8
|
+
private readonly ctx?;
|
|
8
9
|
get CommandRegistryClass(): typeof CommandRegistry;
|
|
9
10
|
get HelpCommandClass(): typeof HelpCommand;
|
|
10
11
|
get ExceptionHandlerClass(): typeof ExceptionHandler;
|
|
11
|
-
constructor();
|
|
12
|
+
constructor(ctx?: C);
|
|
12
13
|
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
13
14
|
registerCommand(command: Command): void;
|
|
14
15
|
runCommand(command: string, ...args: any[]): Promise<number>;
|
package/dist/Cli.js
CHANGED
|
@@ -10,6 +10,7 @@ const ExceptionHandler_1 = require("./ExceptionHandler");
|
|
|
10
10
|
class Cli {
|
|
11
11
|
commandRegistry;
|
|
12
12
|
exceptionHandler;
|
|
13
|
+
ctx;
|
|
13
14
|
get CommandRegistryClass() {
|
|
14
15
|
return CommandRegistry_1.CommandRegistry;
|
|
15
16
|
}
|
|
@@ -19,7 +20,8 @@ class Cli {
|
|
|
19
20
|
get ExceptionHandlerClass() {
|
|
20
21
|
return ExceptionHandler_1.ExceptionHandler;
|
|
21
22
|
}
|
|
22
|
-
constructor() {
|
|
23
|
+
constructor(ctx) {
|
|
24
|
+
this.ctx = ctx;
|
|
23
25
|
this.commandRegistry = new this.CommandRegistryClass();
|
|
24
26
|
this.exceptionHandler = new this.ExceptionHandlerClass();
|
|
25
27
|
this.registerCommand(new this.HelpCommandClass(this.commandRegistry));
|
|
@@ -31,7 +33,7 @@ class Cli {
|
|
|
31
33
|
this.commandRegistry.registerCommand(command);
|
|
32
34
|
}
|
|
33
35
|
async runCommand(command, ...args) {
|
|
34
|
-
return await this.commandRegistry.runCommand(command, ...args)
|
|
36
|
+
return await this.commandRegistry.runCommand(this.ctx, command, ...args)
|
|
35
37
|
.catch(this.exceptionHandler.handle);
|
|
36
38
|
}
|
|
37
39
|
}
|
package/dist/Command.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ export type CommandExample = {
|
|
|
4
4
|
description: string;
|
|
5
5
|
command: string;
|
|
6
6
|
};
|
|
7
|
-
export declare abstract class Command extends CommandHelper {
|
|
7
|
+
export declare abstract class Command<C = undefined> extends CommandHelper {
|
|
8
8
|
abstract signature: string;
|
|
9
9
|
abstract description: string;
|
|
10
|
+
protected ctx: C;
|
|
10
11
|
protected helperDefinitions: {
|
|
11
12
|
[key: string]: string;
|
|
12
13
|
};
|
|
@@ -14,7 +15,7 @@ export declare abstract class Command extends CommandHelper {
|
|
|
14
15
|
protected parser: Parser;
|
|
15
16
|
get command(): string;
|
|
16
17
|
protected abstract handle(): Promise<void | number>;
|
|
17
|
-
run(...args: any[]): Promise<number>;
|
|
18
|
+
run(ctx: C, ...args: any[]): Promise<number>;
|
|
18
19
|
protected option(key: string, defaultValue?: any): string | null;
|
|
19
20
|
protected argument(key: string, defaultValue?: any): string | null;
|
|
20
21
|
}
|
package/dist/Command.js
CHANGED
|
@@ -4,16 +4,21 @@ 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
|
+
ctx;
|
|
7
8
|
helperDefinitions = {};
|
|
8
9
|
commandsExamples = [];
|
|
9
10
|
parser;
|
|
10
11
|
get command() {
|
|
12
|
+
if (this.parser) {
|
|
13
|
+
return this.parser.command;
|
|
14
|
+
}
|
|
11
15
|
return this.signature.split(' ')[0];
|
|
12
16
|
}
|
|
13
|
-
async run(...args) {
|
|
17
|
+
async run(ctx, ...args) {
|
|
18
|
+
this.ctx = ctx;
|
|
14
19
|
this.parser = new Parser_1.Parser(this.signature, this.helperDefinitions, ...args);
|
|
15
20
|
if (args.includes('--help') || args.includes('-h')) {
|
|
16
|
-
return this.help.
|
|
21
|
+
return this.help.call(this);
|
|
17
22
|
}
|
|
18
23
|
this.parser.validate();
|
|
19
24
|
return (await this.handle()) ?? 0;
|
package/dist/CommandHelper.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export declare class CommandRegistry {
|
|
|
7
7
|
getCommands(): Command[];
|
|
8
8
|
registerCommand(command: Command, force?: boolean): void;
|
|
9
9
|
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
10
|
-
runCommand(command: string, ...args: any[]): Promise<number>;
|
|
10
|
+
runCommand(ctx: any, command: string, ...args: any[]): Promise<number>;
|
|
11
11
|
private listCommandsFiles;
|
|
12
12
|
}
|
package/dist/CommandRegistry.js
CHANGED
|
@@ -71,12 +71,12 @@ class CommandRegistry {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
async runCommand(command, ...args) {
|
|
74
|
+
async runCommand(ctx, command, ...args) {
|
|
75
75
|
const commandToRun = this.commands[command];
|
|
76
76
|
if (!this.commands[command]) {
|
|
77
77
|
throw new CommandNotFoundError_1.CommandNotFoundError(command, this.getAvailableCommands());
|
|
78
78
|
}
|
|
79
|
-
return await commandToRun.run(...args);
|
|
79
|
+
return await commandToRun.run(ctx, ...args);
|
|
80
80
|
}
|
|
81
81
|
async *listCommandsFiles(basePath) {
|
|
82
82
|
const dirEntry = fs.readdirSync(basePath, { withFileTypes: true });
|