bob-core 2.0.0-beta.4 → 2.0.0-beta.6
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/cjs/index.js +4 -4
- package/dist/cjs/{package-CXW_8mWb.cjs → package-BKcK1zXi.cjs} +1 -1
- package/dist/cjs/src/Command.d.ts +11 -6
- package/dist/cjs/src/CommandIO.d.ts +9 -0
- package/dist/cjs/src/CommandParser.d.ts +17 -1
- package/dist/cjs/src/CommandRegistry.d.ts +3 -1
- package/dist/cjs/src/CommandSignatureParser.d.ts +1 -47
- package/dist/cjs/src/CommandWithSignature.d.ts +1 -10
- package/dist/cjs/src/errors/index.d.ts +0 -2
- package/dist/cjs/src/lib/optionHelpers.d.ts +1 -1
- package/dist/cjs/src/lib/types.d.ts +2 -2
- package/dist/esm/index.js +560 -652
- package/dist/esm/{package-ye8xt3By.js → package-B_VxJm2q.js} +1 -1
- package/dist/esm/src/Command.d.ts +11 -6
- package/dist/esm/src/CommandIO.d.ts +9 -0
- package/dist/esm/src/CommandParser.d.ts +17 -1
- package/dist/esm/src/CommandRegistry.d.ts +3 -1
- package/dist/esm/src/CommandSignatureParser.d.ts +1 -47
- package/dist/esm/src/CommandWithSignature.d.ts +1 -10
- package/dist/esm/src/errors/index.d.ts +0 -2
- package/dist/esm/src/lib/optionHelpers.d.ts +1 -1
- package/dist/esm/src/lib/types.d.ts +2 -2
- package/package.json +1 -1
- package/dist/cjs/src/errors/MissingSignatureArgument.d.ts +0 -8
- package/dist/cjs/src/errors/MissingSignatureOption.d.ts +0 -8
- package/dist/esm/src/errors/MissingSignatureArgument.d.ts +0 -8
- package/dist/esm/src/errors/MissingSignatureOption.d.ts +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const s = "bob-core", t = "2.0.0-beta.
|
|
1
|
+
const s = "bob-core", t = "2.0.0-beta.6", e = "BOB Core", i = "module", l = !1, n = ["dist/**"], r = { ".": { import: "./dist/esm/index.js", require: "./dist/cjs/index.js" } }, o = { "*": { "*": ["./dist/cjs/*.d.ts"] } }, c = { start: "node -r @swc-node/register debug/main.ts", build: "rimraf ./dist && vite build", typecheck: "tsc --noEmit", prepare: "npm run build", test: "vitest run" }, d = "Léo Hubert", p = "ISC", a = { "@faker-js/faker": "^10.0.0", "@swc-node/register": "^1.11.1", "@types/minimist": "^1.2.5", "@types/node": "^20.14.5", "@types/prompts": "^2.4.9", "@types/string-similarity": "^4.0.2", "@vitest/coverage-v8": "^3.2.4", rimraf: "^6.0.1", tsx: "^4.20.6", typescript: "^5.7.3", vite: "^7.1.6", "vite-plugin-dts": "^4.5.4", vitest: "^3.2.4" }, m = { chalk: "^4.1.2", minimist: "^1.2.8", prompts: "^2.4.2", "string-similarity": "^4.0.4" }, u = {
|
|
2
2
|
name: s,
|
|
3
3
|
version: t,
|
|
4
4
|
description: e,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OptionsSchema, OptionsObject, ArgumentsSchema, ArgumentsObject } from './lib/types.js';
|
|
2
2
|
import { CommandParser } from './CommandParser.js';
|
|
3
|
-
import { CommandSignatureParser } from './CommandSignatureParser.js';
|
|
4
3
|
import { CommandOption } from './contracts/index.js';
|
|
5
4
|
import { CommandIO } from './CommandIO.js';
|
|
6
5
|
import { Logger } from './Logger.js';
|
|
@@ -28,29 +27,35 @@ export type CommandExample = {
|
|
|
28
27
|
export declare class Command<C = any, Options extends OptionsSchema = {}, Arguments extends ArgumentsSchema = {}> {
|
|
29
28
|
readonly _command: string;
|
|
30
29
|
readonly description: string;
|
|
30
|
+
readonly group?: string;
|
|
31
31
|
protected commandsExamples: CommandExample[];
|
|
32
32
|
get command(): string;
|
|
33
33
|
protected ctx: C;
|
|
34
34
|
protected io: CommandIO;
|
|
35
35
|
protected logger: Logger;
|
|
36
|
-
protected _handler?: CommandHandler<C, Options, Arguments>;
|
|
37
36
|
protected parser: CommandParser<Options, Arguments>;
|
|
37
|
+
protected disablePromptingFlag: boolean;
|
|
38
|
+
protected preHandle?(): Promise<void | number>;
|
|
39
|
+
protected _preHandler?: CommandHandler<C, Options, Arguments>;
|
|
40
|
+
protected handle?(ctx: C, opts: CommandHandlerOptions<Options, Arguments>): Promise<number | void> | number | void;
|
|
41
|
+
protected _handler?: CommandHandler<C, Options, Arguments>;
|
|
38
42
|
private tmp?;
|
|
39
43
|
protected defaultOptions(): CommandOption<Command<any, any, any>>[];
|
|
40
44
|
protected newCommandParser(opts: {
|
|
41
45
|
io: CommandIO;
|
|
42
46
|
options: Options;
|
|
43
47
|
arguments: Arguments;
|
|
44
|
-
}): CommandParser<Options, Arguments
|
|
48
|
+
}): CommandParser<Options, Arguments>;
|
|
45
49
|
protected newCommandIO(opts: {
|
|
46
50
|
logger: Logger;
|
|
47
51
|
}): CommandIO;
|
|
48
52
|
constructor(command: string, opts?: {
|
|
49
53
|
description?: string;
|
|
54
|
+
group?: string;
|
|
50
55
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
handler(handler: CommandHandler<C, Options, Arguments>):
|
|
56
|
+
disablePrompting(): this;
|
|
57
|
+
preHandler(handler: CommandHandler<C, Options, Arguments>): this;
|
|
58
|
+
handler(handler: CommandHandler<C, Options, Arguments>): this;
|
|
54
59
|
options<Opts extends OptionsSchema>(opts: Opts): Command<C, Options & Opts, Arguments>;
|
|
55
60
|
arguments<Args extends ArgumentsSchema>(args: Args): Command<C, Options, Arguments & Args>;
|
|
56
61
|
run(opts: CommandRunOption<C, Options, Arguments>): Promise<number | void>;
|
|
@@ -27,6 +27,15 @@ export declare class CommandIO {
|
|
|
27
27
|
min?: number;
|
|
28
28
|
max?: number;
|
|
29
29
|
}): Promise<string | null>;
|
|
30
|
+
askForDate(message: string, defaultValue?: Date, opts?: {
|
|
31
|
+
validate?: (value: Date) => boolean | string;
|
|
32
|
+
mask?: string;
|
|
33
|
+
}): Promise<Date | null>;
|
|
34
|
+
askForList(message: string, defaultValue?: string | number, opts?: {
|
|
35
|
+
validate?: (value: string[]) => boolean | string;
|
|
36
|
+
format?: (value: string) => string;
|
|
37
|
+
separator?: string;
|
|
38
|
+
}): Promise<string[] | null>;
|
|
30
39
|
askForToggle(message: string, defaultValue?: boolean, opts?: {
|
|
31
40
|
active?: string;
|
|
32
41
|
inactive?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionsSchema, OptionReturnType, OptionsObject } from './lib/types.js';
|
|
1
|
+
import { OptionsSchema, OptionReturnType, OptionsObject, OptionDefinition } from './lib/types.js';
|
|
2
2
|
import { OptionDetails } from './lib/optionHelpers.js';
|
|
3
3
|
import { CommandIO } from './CommandIO.js';
|
|
4
4
|
/**
|
|
@@ -11,6 +11,7 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
11
11
|
protected arguments: Arguments;
|
|
12
12
|
protected parsedArguments: OptionsObject<Arguments> | null;
|
|
13
13
|
protected io: CommandIO;
|
|
14
|
+
protected shouldPromptForMissingOptions: boolean;
|
|
14
15
|
constructor(opts: {
|
|
15
16
|
io: CommandIO;
|
|
16
17
|
options: Options;
|
|
@@ -39,6 +40,7 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
39
40
|
* @throws {Error} If init() has not been called yet
|
|
40
41
|
*/
|
|
41
42
|
option<OptsName extends keyof Options>(name: OptsName): OptionReturnType<Options[OptsName]>;
|
|
43
|
+
setOption<OptsName extends keyof Options>(name: OptsName, value: OptionReturnType<Options[OptsName]>): void;
|
|
42
44
|
/**
|
|
43
45
|
* Retrieves a parsed argument value by name
|
|
44
46
|
* @param name - The argument name
|
|
@@ -46,6 +48,7 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
46
48
|
* @throws {Error} If init() has not been called yet
|
|
47
49
|
*/
|
|
48
50
|
argument<ArgName extends keyof Arguments>(name: ArgName): OptionReturnType<Arguments[ArgName]>;
|
|
51
|
+
setArgument<ArgName extends keyof Arguments>(name: ArgName, value: OptionReturnType<Arguments[ArgName]>): void;
|
|
49
52
|
/**
|
|
50
53
|
* Validates that all provided options are recognized
|
|
51
54
|
* @throws {InvalidOption} If an unknown option is found
|
|
@@ -77,4 +80,17 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
77
80
|
argumentDefinitions(): Record<string, OptionDetails>;
|
|
78
81
|
availableOptions(): string[];
|
|
79
82
|
availableArguments(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Disables prompting for missing argument values
|
|
85
|
+
* Useful for non-interactive environments
|
|
86
|
+
*/
|
|
87
|
+
disablePrompting(): this;
|
|
88
|
+
/**
|
|
89
|
+
* Prompts the user to provide a missing argument value via CommandIO
|
|
90
|
+
* Used by validate() when shouldPromptForMissingArgs is enabled
|
|
91
|
+
* @param argumentName - The name of the missing argument
|
|
92
|
+
* @param argDef - The argument's definition for type and description
|
|
93
|
+
* @returns The user-provided value, or null if none given
|
|
94
|
+
*/
|
|
95
|
+
protected promptForArgument(argumentName: string, argDef: OptionDefinition): Promise<string | number | string[] | null>;
|
|
80
96
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommandIO } from './CommandIO.js';
|
|
2
2
|
import { Command } from './Command.js';
|
|
3
3
|
import { Logger } from './Logger.js';
|
|
4
|
-
export type CommandResolver = (path: string) => Promise<Command>;
|
|
4
|
+
export type CommandResolver = (path: string) => Promise<Command | null>;
|
|
5
5
|
export declare class CommandRegistry {
|
|
6
6
|
private readonly commands;
|
|
7
7
|
protected readonly io: CommandIO;
|
|
@@ -12,6 +12,8 @@ export declare class CommandRegistry {
|
|
|
12
12
|
getCommands(): Array<Command>;
|
|
13
13
|
private commandResolver;
|
|
14
14
|
setCommandResolver(resolver: CommandResolver): void;
|
|
15
|
+
fileCheck: (filePath: string) => boolean;
|
|
16
|
+
setFileCheck(check: (filePath: string) => boolean): this;
|
|
15
17
|
registerCommand(command: Command<any, any, any>, force?: boolean): void;
|
|
16
18
|
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
17
19
|
runCommand(ctx: any, command: string | Command, ...args: any[]): Promise<number>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommandOption } from './contracts/index.js';
|
|
2
2
|
import { CommandIO } from './CommandIO.js';
|
|
3
|
-
import {
|
|
3
|
+
import { OptionsSchema } from './lib/types.js';
|
|
4
4
|
import { CommandParser } from './CommandParser.js';
|
|
5
5
|
/**
|
|
6
6
|
* Extends CommandParser to parse command signatures like "command {arg} {--option}"
|
|
@@ -8,8 +8,6 @@ import { CommandParser } from './CommandParser.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class CommandSignatureParser<Opts extends OptionsSchema = any, Args extends OptionsSchema = any> extends CommandParser<Opts, Args> {
|
|
10
10
|
readonly command: string;
|
|
11
|
-
private readonly argumentsSchema;
|
|
12
|
-
private readonly optionsSchema;
|
|
13
11
|
constructor(opts: {
|
|
14
12
|
io: CommandIO;
|
|
15
13
|
signature: string;
|
|
@@ -23,38 +21,6 @@ export declare class CommandSignatureParser<Opts extends OptionsSchema = any, Ar
|
|
|
23
21
|
* Example: "migrate {name} {--force}" -> { command: "migrate", arguments: {name: ...}, options: {force: ...} }
|
|
24
22
|
*/
|
|
25
23
|
private static parseSignature;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves an option value by name, with signature validation
|
|
28
|
-
*/
|
|
29
|
-
option(name: any): any;
|
|
30
|
-
/**
|
|
31
|
-
* Sets an option value programmatically
|
|
32
|
-
*/
|
|
33
|
-
setOption(name: string, value: any): void;
|
|
34
|
-
/**
|
|
35
|
-
* Retrieves the description/help text for an option
|
|
36
|
-
*/
|
|
37
|
-
optionHelp(name: string): string | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves the description/help text for an argument
|
|
40
|
-
*/
|
|
41
|
-
argumentHelp(name: string): string | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves an argument value by name, with signature validation
|
|
44
|
-
*/
|
|
45
|
-
argument(name: any): any;
|
|
46
|
-
/**
|
|
47
|
-
* Sets an argument value programmatically
|
|
48
|
-
*/
|
|
49
|
-
setArgument(name: string, value: any): void;
|
|
50
|
-
/**
|
|
51
|
-
* Returns all argument definitions from the signature
|
|
52
|
-
*/
|
|
53
|
-
getArgumentSignatures(): OptionsSchema;
|
|
54
|
-
/**
|
|
55
|
-
* Returns all option definitions from the signature
|
|
56
|
-
*/
|
|
57
|
-
getOptionSignatures(): OptionsSchema;
|
|
58
24
|
/**
|
|
59
25
|
* Parses a single parameter signature like "{name}" or "{--force}" or "{files*}"
|
|
60
26
|
* Extracts name, type, default value, aliases, description, etc.
|
|
@@ -70,16 +36,4 @@ export declare class CommandSignatureParser<Opts extends OptionsSchema = any, Ar
|
|
|
70
36
|
* - {--opt|o} -> option with alias
|
|
71
37
|
*/
|
|
72
38
|
private static parseParamSignature;
|
|
73
|
-
/**
|
|
74
|
-
* Validates that all required arguments are present
|
|
75
|
-
* If missing, prompts the user via CommandIO to provide them
|
|
76
|
-
* @throws {MissingRequiredArgumentValue} If a required argument cannot be obtained
|
|
77
|
-
*/
|
|
78
|
-
validate(): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Prompts the user to provide a missing argument value via CommandIO
|
|
81
|
-
*/
|
|
82
|
-
private promptForArgument;
|
|
83
|
-
optionValues(): OptionsObject<Opts>;
|
|
84
|
-
argumentValues(): OptionsObject<Args>;
|
|
85
39
|
}
|
|
@@ -14,22 +14,13 @@ export declare abstract class CommandWithSignature<C = any, Opts extends Options
|
|
|
14
14
|
io: CommandIO;
|
|
15
15
|
options: Opts;
|
|
16
16
|
arguments: Args;
|
|
17
|
-
}): CommandSignatureParser
|
|
17
|
+
}): CommandSignatureParser<Opts, Args>;
|
|
18
18
|
constructor();
|
|
19
19
|
protected abstract handle(ctx: C, opts: CommandHandlerOptions<Opts, Args>): Promise<number | void>;
|
|
20
|
-
protected setOption(name: string, value: any): void;
|
|
21
|
-
protected setArgument(name: string, value: any): void;
|
|
22
20
|
protected option<T = string>(key: string): T | null;
|
|
23
21
|
protected option<T = string>(key: string, defaultValue: T): NoInfer<T>;
|
|
24
|
-
protected optionBoolean(key: string, defaultValue?: boolean): boolean;
|
|
25
|
-
protected optionArray<T = string>(key: string, defaultValue?: Array<T>): Array<NoInfer<T>>;
|
|
26
|
-
protected optionNumber(key: string): number | null;
|
|
27
|
-
protected optionNumber(key: string, defaultValue: number): number;
|
|
28
22
|
protected argument<T = string>(key: string): T | null;
|
|
29
23
|
protected argument<T = string>(key: string, defaultValue: T): NoInfer<T>;
|
|
30
|
-
protected argumentArray<T = string>(key: string, defaultValue?: Array<any>): Array<T>;
|
|
31
|
-
protected argumentBoolean(key: string, defaultValue?: boolean): boolean;
|
|
32
|
-
protected argumentNumber(key: string, defaultValue?: number | null): number | null;
|
|
33
24
|
askForConfirmation(...opts: Parameters<typeof this.io.askForConfirmation>): ReturnType<typeof this.io.askForConfirmation>;
|
|
34
25
|
askForInput(...opts: Parameters<typeof this.io.askForInput>): ReturnType<typeof this.io.askForInput>;
|
|
35
26
|
askForSelect(...opts: Parameters<typeof this.io.askForSelect>): ReturnType<typeof this.io.askForSelect>;
|
|
@@ -3,7 +3,5 @@ export * from './BadCommandParameter.js';
|
|
|
3
3
|
export * from './BadCommandOption.js';
|
|
4
4
|
export * from './InvalidOption.js';
|
|
5
5
|
export * from './CommandNotFoundError.js';
|
|
6
|
-
export * from './MissingSignatureArgument.js';
|
|
7
|
-
export * from './MissingSignatureOption.js';
|
|
8
6
|
export * from './MissingRequiredArgumentValue.js';
|
|
9
7
|
export * from './MissingRequiredOptionValue.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option, OptionDefinition, OptionReturnType } from './types.js';
|
|
2
2
|
export declare function getOptionPrimitiveDefaultValue<Opts extends Option>(type: Opts): OptionReturnType<Opts>;
|
|
3
|
-
export declare function getOptionDefaultValue<Opts extends Option>(option: Opts): OptionReturnType<Opts
|
|
3
|
+
export declare function getOptionDefaultValue<Opts extends Option>(option: Opts): OptionReturnType<Opts> | null;
|
|
4
4
|
export type OptionDetails = Required<OptionDefinition>;
|
|
5
5
|
export declare function getOptionDetails(option: Option): OptionDetails;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type OptionPrimitive = 'string' | 'number' | 'boolean' | ['string'] | ['number'];
|
|
1
|
+
export type OptionPrimitive = 'secret' | 'string' | 'number' | 'boolean' | ['string'] | ['number'];
|
|
2
2
|
export type OptionDefinition = {
|
|
3
3
|
type: OptionPrimitive;
|
|
4
4
|
description?: string;
|
|
@@ -8,7 +8,7 @@ export type OptionDefinition = {
|
|
|
8
8
|
variadic?: boolean;
|
|
9
9
|
};
|
|
10
10
|
export type Option = OptionPrimitive | OptionDefinition;
|
|
11
|
-
export type OptionType<O extends Option> = O extends 'string' ? string : O extends 'number' ? number : O extends 'boolean' ? boolean : O extends Array<'string'> ? Array<string> : O extends Array<'number'> ? Array<number> : O extends {
|
|
11
|
+
export type OptionType<O extends Option> = O extends 'secret' ? string : O extends 'string' ? string : O extends 'number' ? number : O extends 'boolean' ? boolean : O extends Array<'string'> ? Array<string> : O extends Array<'number'> ? Array<number> : O extends {
|
|
12
12
|
type: infer T extends Option;
|
|
13
13
|
} ? OptionType<T> : never;
|
|
14
14
|
export type IsRequired<O extends Option> = O extends {
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BobError } from './BobError.js';
|
|
2
|
-
import { OptionsSchema } from '../lib/types.js';
|
|
3
|
-
export declare class MissingSignatureArgument extends BobError {
|
|
4
|
-
private argument;
|
|
5
|
-
private argumentsSchema;
|
|
6
|
-
constructor(argument: string, argumentsSchema: OptionsSchema);
|
|
7
|
-
pretty(io: any): void;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BobError } from './BobError.js';
|
|
2
|
-
import { OptionsSchema } from '../lib/types.js';
|
|
3
|
-
export declare class MissingSignatureOption extends BobError {
|
|
4
|
-
private option;
|
|
5
|
-
private optionsSchema;
|
|
6
|
-
constructor(option: string, optionsSchema: OptionsSchema);
|
|
7
|
-
pretty(io: any): void;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BobError } from './BobError.js';
|
|
2
|
-
import { OptionsSchema } from '../lib/types.js';
|
|
3
|
-
export declare class MissingSignatureArgument extends BobError {
|
|
4
|
-
private argument;
|
|
5
|
-
private argumentsSchema;
|
|
6
|
-
constructor(argument: string, argumentsSchema: OptionsSchema);
|
|
7
|
-
pretty(io: any): void;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BobError } from './BobError.js';
|
|
2
|
-
import { OptionsSchema } from '../lib/types.js';
|
|
3
|
-
export declare class MissingSignatureOption extends BobError {
|
|
4
|
-
private option;
|
|
5
|
-
private optionsSchema;
|
|
6
|
-
constructor(option: string, optionsSchema: OptionsSchema);
|
|
7
|
-
pretty(io: any): void;
|
|
8
|
-
}
|