bob-core 2.1.0 → 3.0.0-alpha.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/cjs/package-Brk9TOly.cjs +1 -0
- package/dist/cjs/src/Cli.d.ts +4 -6
- package/dist/cjs/src/Command.d.ts +27 -50
- package/dist/cjs/src/CommandParser.d.ts +48 -50
- package/dist/cjs/src/CommandRegistry.d.ts +5 -5
- package/dist/cjs/src/CommandSignatureParser.d.ts +22 -25
- package/dist/cjs/src/CommandWithSignature.d.ts +19 -23
- package/dist/cjs/src/Flags.d.ts +25 -0
- package/dist/cjs/src/commands/HelpCommand.d.ts +2 -0
- package/dist/cjs/src/contracts/index.d.ts +0 -1
- package/dist/cjs/src/errors/BadCommandArgument.d.ts +14 -0
- package/dist/cjs/src/errors/BadCommandFlag.d.ts +14 -0
- package/dist/cjs/src/errors/InvalidFlag.d.ts +9 -0
- package/dist/cjs/src/errors/MissingRequiredFlagValue.d.ts +7 -0
- package/dist/cjs/src/errors/index.d.ts +4 -4
- package/dist/cjs/src/index.d.ts +3 -2
- package/dist/cjs/src/index.js +5 -14
- package/dist/cjs/src/lib/helpers.d.ts +1 -0
- package/dist/cjs/src/lib/types.d.ts +72 -18
- package/dist/cjs/src/options/HelpOption.d.ts +11 -10
- package/dist/esm/package-DAxovIBA.js +59 -0
- package/dist/esm/src/Cli.d.ts +4 -6
- package/dist/esm/src/Command.d.ts +27 -50
- package/dist/esm/src/CommandParser.d.ts +48 -50
- package/dist/esm/src/CommandRegistry.d.ts +5 -5
- package/dist/esm/src/CommandSignatureParser.d.ts +22 -25
- package/dist/esm/src/CommandWithSignature.d.ts +19 -23
- package/dist/esm/src/Flags.d.ts +25 -0
- package/dist/esm/src/commands/HelpCommand.d.ts +2 -0
- package/dist/esm/src/contracts/index.d.ts +0 -1
- package/dist/esm/src/errors/BadCommandArgument.d.ts +14 -0
- package/dist/esm/src/errors/BadCommandFlag.d.ts +14 -0
- package/dist/esm/src/errors/InvalidFlag.d.ts +9 -0
- package/dist/esm/src/errors/MissingRequiredFlagValue.d.ts +7 -0
- package/dist/esm/src/errors/index.d.ts +4 -4
- package/dist/esm/src/index.d.ts +3 -2
- package/dist/esm/src/index.js +926 -1070
- package/dist/esm/src/lib/helpers.d.ts +1 -0
- package/dist/esm/src/lib/types.d.ts +72 -18
- package/dist/esm/src/options/HelpOption.d.ts +11 -10
- package/package.json +11 -12
- package/dist/cjs/package-DYSfqWOt.cjs +0 -1
- package/dist/cjs/src/contracts/CommandOption.d.ts +0 -6
- package/dist/cjs/src/errors/BadCommandOption.d.ts +0 -12
- package/dist/cjs/src/errors/BadCommandParameter.d.ts +0 -12
- package/dist/cjs/src/errors/InvalidOption.d.ts +0 -9
- package/dist/cjs/src/errors/MissingRequiredOptionValue.d.ts +0 -7
- package/dist/cjs/src/lib/optionHelpers.d.ts +0 -5
- package/dist/cjs/src/lib/valueConverter.d.ts +0 -10
- package/dist/esm/package-uVOgoItG.js +0 -33
- package/dist/esm/src/contracts/CommandOption.d.ts +0 -6
- package/dist/esm/src/errors/BadCommandOption.d.ts +0 -12
- package/dist/esm/src/errors/BadCommandParameter.d.ts +0 -12
- package/dist/esm/src/errors/InvalidOption.d.ts +0 -9
- package/dist/esm/src/errors/MissingRequiredOptionValue.d.ts +0 -7
- package/dist/esm/src/lib/optionHelpers.d.ts +0 -5
- package/dist/esm/src/lib/valueConverter.d.ts +0 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={name:`bob-core`,version:`3.0.0-alpha.1`,description:`BOB Core`,type:`module`,main:`./dist/cjs/src/index.js`,module:`./dist/esm/src/index.js`,types:`./dist/esm/src/index.d.ts`,files:[`dist`],exports:{".":{import:{types:`./dist/esm/src/index.d.ts`,default:`./dist/esm/src/index.js`},require:{types:`./dist/cjs/src/index.d.ts`,default:`./dist/cjs/src/index.js`}}},scripts:{start:`node -r @swc-node/register debug/main.ts`,build:`rm -rf ./dist && vite build`,typecheck:`tsc --noEmit`,prepack:`npm run build`,test:`vitest run`,lint:`eslint .`,"lint:fix":`eslint . --fix`},author:`Léo Hubert`,license:`ISC`,devDependencies:{"@eslint/js":`^9.39.4`,"@faker-js/faker":`^10.3.0`,"@swc-node/register":`^1.11.1`,"@trivago/prettier-plugin-sort-imports":`^5.2.2`,"@types/minimist":`^1.2.5`,"@types/node":`^20.14.5`,"@types/prompts":`^2.4.9`,"@types/string-similarity":`^4.0.2`,"@vitest/coverage-v8":`^4.1.0`,eslint:`^9.39.4`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,prettier:`^3.6.2`,tsx:`^4.21.0`,typescript:`^5.9.3`,"typescript-eslint":`^8.57.0`,vite:`^8.0.0`,"vite-plugin-dts":`^4.5.4`,vitest:`^4.1.0`},dependencies:{chalk:`^4.1.2`,minimist:`^1.2.8`,prompts:`^2.4.2`}};exports.default=e;
|
package/dist/cjs/src/Cli.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CommandRegistry, CommandRegistryOptions, CommandResolver, FileImporter
|
|
|
3
3
|
import { ExceptionHandler } from './ExceptionHandler.js';
|
|
4
4
|
import { Logger } from './Logger.js';
|
|
5
5
|
import { default as HelpCommand, HelpCommandOptions } from './commands/HelpCommand.js';
|
|
6
|
-
import { ContextDefinition
|
|
6
|
+
import { ContextDefinition } from './lib/types.js';
|
|
7
7
|
export type CliOptions<C extends ContextDefinition = ContextDefinition> = {
|
|
8
8
|
ctx?: C;
|
|
9
9
|
name?: string;
|
|
@@ -24,10 +24,8 @@ export declare class Cli<C extends ContextDefinition = ContextDefinition> {
|
|
|
24
24
|
constructor(opts?: CliOptions<C>);
|
|
25
25
|
withCommandResolver(resolver: CommandResolver): this;
|
|
26
26
|
withFileImporter(importer: FileImporter): this;
|
|
27
|
-
withCommands(...commands: Array<Command<C
|
|
28
|
-
|
|
29
|
-
} | string>): Promise<void>;
|
|
30
|
-
runCommand(command: string | Command | undefined, ...args: string[]): Promise<number>;
|
|
27
|
+
withCommands(...commands: Array<typeof Command<C> | Command<C> | string>): Promise<void>;
|
|
28
|
+
runCommand(command: string | typeof Command | Command | undefined, ...args: string[]): Promise<number>;
|
|
31
29
|
runHelpCommand(): Promise<number>;
|
|
32
|
-
protected registerCommand(command: Command<C
|
|
30
|
+
protected registerCommand(command: typeof Command<C>): void;
|
|
33
31
|
}
|
|
@@ -1,68 +1,45 @@
|
|
|
1
1
|
import { CommandIO, CommandIOOptions } from './CommandIO.js';
|
|
2
2
|
import { CommandParser } from './CommandParser.js';
|
|
3
3
|
import { Logger } from './Logger.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
arguments: ArgumentsObject<Arguments>;
|
|
4
|
+
import { ArgumentsSchema, ContextDefinition, FlagsSchema, Parsed } from './lib/types.js';
|
|
5
|
+
export type CommandRunExample = {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
9
8
|
};
|
|
10
|
-
export type
|
|
11
|
-
export type CommandRunOption<C, Options extends OptionsSchema, Arguments extends ArgumentsSchema> = {
|
|
9
|
+
export type CommandRunOption<C = ContextDefinition> = {
|
|
12
10
|
logger: Logger;
|
|
13
11
|
ctx: C;
|
|
14
12
|
} & ({
|
|
15
13
|
args: string[];
|
|
16
14
|
} | {
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
args: Record<string, any>;
|
|
16
|
+
flags: Record<string, any>;
|
|
19
17
|
});
|
|
20
|
-
export
|
|
21
|
-
description: string;
|
|
22
|
-
command: string;
|
|
23
|
-
};
|
|
24
|
-
export declare class Command<C extends ContextDefinition = ContextDefinition, Options extends OptionsSchema = OptionsSchema, Arguments extends ArgumentsSchema = ArgumentsSchema> {
|
|
18
|
+
export declare abstract class Command<C extends ContextDefinition = ContextDefinition> {
|
|
25
19
|
$type: "BobCommand";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
static command: string;
|
|
21
|
+
static description: string;
|
|
22
|
+
static group?: string;
|
|
23
|
+
static args: ArgumentsSchema;
|
|
24
|
+
static flags: FlagsSchema;
|
|
25
|
+
static examples: CommandRunExample[];
|
|
26
|
+
static hidden: boolean;
|
|
27
|
+
static disableDefaultOptions: boolean;
|
|
28
|
+
static disablePrompting: boolean;
|
|
29
|
+
static allowUnknownFlags: boolean;
|
|
30
|
+
static strictMode: boolean;
|
|
31
31
|
protected ctx: C;
|
|
32
32
|
protected io: CommandIO;
|
|
33
|
-
protected parser: CommandParser<
|
|
34
|
-
protected disablePromptingFlag: boolean;
|
|
35
|
-
protected allowUnknownOptionsFlag: boolean;
|
|
36
|
-
protected hiddenFlag: boolean;
|
|
37
|
-
protected disableDefaultOptionsFlag: boolean;
|
|
38
|
-
protected strictModeFlag: boolean;
|
|
33
|
+
protected parser: CommandParser<FlagsSchema, FlagsSchema>;
|
|
39
34
|
protected preHandle?(): Promise<void | number>;
|
|
40
|
-
protected
|
|
41
|
-
|
|
42
|
-
protected _handler?: CommandHandler<C, Options, Arguments>;
|
|
43
|
-
private tmp?;
|
|
44
|
-
protected defaultOptions(): CommandOption<Command>[];
|
|
35
|
+
protected abstract handle(ctx: C, parsed: Parsed<any>): Promise<number | void> | number | void;
|
|
36
|
+
static baseFlags: FlagsSchema;
|
|
45
37
|
protected newCommandParser(opts: {
|
|
38
|
+
flags: FlagsSchema;
|
|
39
|
+
args: ArgumentsSchema;
|
|
40
|
+
ctx: ContextDefinition;
|
|
46
41
|
io: CommandIO;
|
|
47
|
-
|
|
48
|
-
arguments: Arguments;
|
|
49
|
-
}): CommandParser<Options, Arguments>;
|
|
42
|
+
}): CommandParser<FlagsSchema, FlagsSchema>;
|
|
50
43
|
protected newCommandIO(opts: CommandIOOptions): CommandIO;
|
|
51
|
-
|
|
52
|
-
description?: string;
|
|
53
|
-
group?: string;
|
|
54
|
-
options?: Options;
|
|
55
|
-
arguments?: Arguments;
|
|
56
|
-
});
|
|
57
|
-
disablePrompting(): this;
|
|
58
|
-
allowUnknownOptions(): this;
|
|
59
|
-
hidden(): this;
|
|
60
|
-
get isHidden(): boolean;
|
|
61
|
-
disableDefaultOptions(): this;
|
|
62
|
-
strictMode(): this;
|
|
63
|
-
preHandler(handler: CommandHandler<C, Options, Arguments>): this;
|
|
64
|
-
handler(handler: CommandHandler<C, Options, Arguments>): this;
|
|
65
|
-
options<Opts extends OptionsSchema>(opts: Opts): Command<C, Options & Opts, Arguments>;
|
|
66
|
-
arguments<Args extends ArgumentsSchema>(args: Args): Command<C, Options, Arguments & Args>;
|
|
67
|
-
run(opts: CommandRunOption<C, Options, Arguments>): Promise<number | void>;
|
|
44
|
+
run(runOpts: CommandRunOption<C>): Promise<number | void>;
|
|
68
45
|
}
|
|
@@ -1,49 +1,55 @@
|
|
|
1
1
|
import { CommandIO } from './CommandIO.js';
|
|
2
|
-
import {
|
|
3
|
-
import { OptionDefinition, OptionReturnType, OptionsObject, OptionsSchema } from './lib/types.js';
|
|
2
|
+
import { ArgumentsSchema, ContextDefinition, FlagDefinition, FlagReturnType, FlagsObject, FlagsSchema } from './lib/types.js';
|
|
4
3
|
/**
|
|
5
|
-
* Parses command-line arguments into typed
|
|
4
|
+
* Parses command-line arguments into typed flags and arguments
|
|
6
5
|
* Handles validation, type conversion, and default values
|
|
7
6
|
*/
|
|
8
|
-
export declare class CommandParser<
|
|
9
|
-
protected
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export declare class CommandParser<Flags extends FlagsSchema, Arguments extends ArgumentsSchema> {
|
|
8
|
+
protected opts: {
|
|
9
|
+
flags: Flags;
|
|
10
|
+
args: Arguments;
|
|
11
|
+
ctx?: ContextDefinition;
|
|
12
|
+
io: CommandIO;
|
|
13
|
+
};
|
|
14
|
+
protected flags: FlagsSchema;
|
|
15
|
+
protected parsedFlags: FlagsObject<Flags> | null;
|
|
16
|
+
protected args: ArgumentsSchema;
|
|
17
|
+
protected parsedArguments: FlagsObject<Arguments> | null;
|
|
13
18
|
protected io: CommandIO;
|
|
14
|
-
protected
|
|
15
|
-
protected
|
|
19
|
+
protected shouldPromptForMissingFlags: boolean;
|
|
20
|
+
protected shouldValidateUnknownFlags: boolean;
|
|
16
21
|
protected shouldRejectExtraArguments: boolean;
|
|
17
22
|
constructor(opts: {
|
|
23
|
+
flags: Flags;
|
|
24
|
+
args: Arguments;
|
|
25
|
+
ctx?: ContextDefinition;
|
|
18
26
|
io: CommandIO;
|
|
19
|
-
options: Options;
|
|
20
|
-
arguments: Arguments;
|
|
21
27
|
});
|
|
22
28
|
/**
|
|
23
|
-
* Parses raw command-line arguments into structured
|
|
29
|
+
* Parses raw command-line arguments into structured flags and arguments
|
|
24
30
|
* @param args - Raw command line arguments (typically from process.argv.slice(2))
|
|
25
|
-
* @returns Object containing parsed
|
|
26
|
-
* @throws {
|
|
27
|
-
* @throws {
|
|
31
|
+
* @returns Object containing parsed flags and arguments
|
|
32
|
+
* @throws {InvalidFlag} If an unknown flag is provided
|
|
33
|
+
* @throws {BadCommandFlag} If a value cannot be converted to the expected type
|
|
28
34
|
*/
|
|
29
|
-
init(args: string[]): {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
35
|
+
init(args: string[]): Promise<{
|
|
36
|
+
flags: FlagsObject<Flags>;
|
|
37
|
+
args: FlagsObject<Arguments>;
|
|
38
|
+
}>;
|
|
33
39
|
/**
|
|
34
|
-
* Validates the parsed
|
|
40
|
+
* Validates the parsed flags and arguments
|
|
35
41
|
* @throws {Error} If validation fails
|
|
36
42
|
*/
|
|
37
43
|
validate(): Promise<void>;
|
|
38
44
|
/**
|
|
39
|
-
* Retrieves a parsed
|
|
40
|
-
* @param name - The
|
|
41
|
-
* @param defaultValue - Optional default value if
|
|
42
|
-
* @returns The typed
|
|
45
|
+
* Retrieves a parsed flag value by name
|
|
46
|
+
* @param name - The flag name
|
|
47
|
+
* @param defaultValue - Optional default value if flag is not set
|
|
48
|
+
* @returns The typed flag value
|
|
43
49
|
* @throws {Error} If init() has not been called yet
|
|
44
50
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
flag<FlagName extends keyof Flags>(name: FlagName, defaultValue?: FlagReturnType<Flags[FlagName]>): FlagReturnType<Flags[FlagName]>;
|
|
52
|
+
setFlag<FlagName extends keyof Flags>(name: FlagName, value: FlagReturnType<Flags[FlagName]>): Promise<void>;
|
|
47
53
|
/**
|
|
48
54
|
* Retrieves a parsed argument value by name
|
|
49
55
|
* @param name - The argument name
|
|
@@ -51,8 +57,8 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
51
57
|
* @returns The typed argument value
|
|
52
58
|
* @throws {Error} If init() has not been called yet
|
|
53
59
|
*/
|
|
54
|
-
argument<ArgName extends keyof Arguments>(name: ArgName, defaultValue?:
|
|
55
|
-
setArgument<ArgName extends keyof Arguments>(name: ArgName, value:
|
|
60
|
+
argument<ArgName extends keyof Arguments>(name: ArgName, defaultValue?: FlagReturnType<Arguments[ArgName]>): FlagReturnType<Arguments[ArgName]>;
|
|
61
|
+
setArgument<ArgName extends keyof Arguments>(name: ArgName, value: FlagReturnType<Arguments[ArgName]>): Promise<void>;
|
|
56
62
|
/**
|
|
57
63
|
* Checks if a value should be considered "empty" for default value purposes
|
|
58
64
|
* @param value - The value to check
|
|
@@ -60,12 +66,12 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
60
66
|
*/
|
|
61
67
|
private isEmptyValue;
|
|
62
68
|
/**
|
|
63
|
-
* Validates that all provided
|
|
64
|
-
* @throws {
|
|
69
|
+
* Validates that all provided flags are recognized
|
|
70
|
+
* @throws {InvalidFlag} If an unknown flag is found
|
|
65
71
|
*/
|
|
66
|
-
private
|
|
72
|
+
private validateUnknownFlags;
|
|
67
73
|
/**
|
|
68
|
-
* Processes named
|
|
74
|
+
* Processes named flags from minimist output
|
|
69
75
|
*/
|
|
70
76
|
private handleOptions;
|
|
71
77
|
/**
|
|
@@ -73,36 +79,28 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
73
79
|
*/
|
|
74
80
|
private handleArguments;
|
|
75
81
|
/**
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
private handleVariadicArgument;
|
|
79
|
-
/**
|
|
80
|
-
* Resolves a single positional argument value with defaults and type conversion
|
|
81
|
-
* Note: Does not validate required arguments - validation happens in subclass validate() methods
|
|
82
|
+
* Resolves a flag value from the parsed flag values object
|
|
83
|
+
* Handles alias resolution, defaults, and type conversion
|
|
82
84
|
*/
|
|
83
|
-
private
|
|
85
|
+
private resolveFlagValue;
|
|
84
86
|
/**
|
|
85
|
-
*
|
|
86
|
-
* Handles alias resolution, defaults, and type conversion
|
|
87
|
+
* Parses a raw value using the flag's parse function
|
|
87
88
|
*/
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
argumentDefinitions(): Record<string, OptionDetails>;
|
|
91
|
-
availableOptions(): string[];
|
|
92
|
-
availableArguments(): string[];
|
|
89
|
+
private parseValue;
|
|
90
|
+
private safeParse;
|
|
93
91
|
/**
|
|
94
92
|
* Disables prompting for missing argument values
|
|
95
93
|
* Useful for non-interactive environments
|
|
96
94
|
*/
|
|
97
95
|
disablePrompting(): this;
|
|
98
|
-
|
|
96
|
+
allowUnknownFlags(): this;
|
|
99
97
|
strictMode(): this;
|
|
100
98
|
/**
|
|
101
99
|
* Prompts the user to provide a missing argument value via CommandIO
|
|
102
100
|
* Used by validate() when shouldPromptForMissingArgs is enabled
|
|
103
101
|
* @param argumentName - The name of the missing argument
|
|
104
|
-
* @param
|
|
102
|
+
* @param definition - The argument's definition for type and description
|
|
105
103
|
* @returns The user-provided value, or null if none given
|
|
106
104
|
*/
|
|
107
|
-
protected promptForArgument(argumentName: string,
|
|
105
|
+
protected promptForArgument(argumentName: string, definition: FlagDefinition): Promise<string | number | string[] | null>;
|
|
108
106
|
}
|
|
@@ -2,8 +2,8 @@ import { Command } from './Command.js';
|
|
|
2
2
|
import { CommandIO, CommandIOOptions } from './CommandIO.js';
|
|
3
3
|
import { Logger } from './Logger.js';
|
|
4
4
|
import { StringSimilarity } from './StringSimilarity.js';
|
|
5
|
-
import {
|
|
6
|
-
export type CommandResolver = (path: string) => Promise<Command | null>;
|
|
5
|
+
import { ContextDefinition } from './lib/types.js';
|
|
6
|
+
export type CommandResolver = (path: string) => Promise<typeof Command | null>;
|
|
7
7
|
export type FileImporter = (filePath: string) => Promise<unknown>;
|
|
8
8
|
export type CommandRegistryOptions = {
|
|
9
9
|
logger?: Logger;
|
|
@@ -17,14 +17,14 @@ export declare class CommandRegistry {
|
|
|
17
17
|
protected newCommandIO(opts: CommandIOOptions): CommandIO;
|
|
18
18
|
constructor(opts?: CommandRegistryOptions);
|
|
19
19
|
getAvailableCommands(): string[];
|
|
20
|
-
getCommands(): Array<Command>;
|
|
20
|
+
getCommands(): Array<typeof Command>;
|
|
21
21
|
private importFile;
|
|
22
22
|
private commandResolver;
|
|
23
23
|
withCommandResolver(resolver: CommandResolver): this;
|
|
24
24
|
withFileImporter(importer: FileImporter): this;
|
|
25
|
-
registerCommand
|
|
25
|
+
registerCommand(command: typeof Command<any>, force?: boolean): void;
|
|
26
26
|
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
27
|
-
runCommand(ctx: ContextDefinition, command: string | Command, ...args: string[]): Promise<number>;
|
|
27
|
+
runCommand(ctx: ContextDefinition, command: string | typeof Command | Command, ...args: string[]): Promise<number>;
|
|
28
28
|
private suggestCommand;
|
|
29
29
|
private askRunSimilarCommand;
|
|
30
30
|
private listCommandsFiles;
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CommandIO } from './CommandIO.js';
|
|
3
|
-
import { CommandParser } from './CommandParser.js';
|
|
4
|
-
import { CommandOption } from './contracts/index.js';
|
|
5
|
-
import { OptionsSchema } from './lib/types.js';
|
|
1
|
+
import { ArgumentsSchema, FlagsSchema } from './lib/types.js';
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* @deprecated This class is deprecated and will be removed in future versions. Use CommandParser with explicit schema definitions instead.
|
|
4
|
+
* Parses command signature strings like "command {arg} {--option}" into
|
|
5
|
+
* FlagsSchema and ArgumentsSchema using Flags/Args factories.
|
|
9
6
|
*/
|
|
10
|
-
export declare class CommandSignatureParser
|
|
11
|
-
readonly command: string;
|
|
12
|
-
constructor(opts: {
|
|
13
|
-
io: CommandIO;
|
|
14
|
-
signature: string;
|
|
15
|
-
helperDefinitions: {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
};
|
|
18
|
-
defaultOptions: CommandOption<Command>[];
|
|
19
|
-
});
|
|
7
|
+
export declare class CommandSignatureParser {
|
|
20
8
|
/**
|
|
21
|
-
* Parses command signature string into command name and
|
|
22
|
-
*
|
|
9
|
+
* Parses a command signature string into command name, flags, and args schemas.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* CommandSignatureParser.parse('migrate {name} {--force}')
|
|
13
|
+
* // => { command: 'migrate', flags: { force: Flags.boolean() }, args: { name: Args.string({ required: true }) } }
|
|
23
14
|
*/
|
|
24
|
-
|
|
15
|
+
static parse(signature: string, helperDefinitions?: Record<string, string>): {
|
|
16
|
+
command: string;
|
|
17
|
+
flags: FlagsSchema;
|
|
18
|
+
args: ArgumentsSchema;
|
|
19
|
+
};
|
|
25
20
|
/**
|
|
26
|
-
* Parses a single parameter signature
|
|
27
|
-
* Extracts name, type, default value, aliases, description, etc.
|
|
21
|
+
* Parses a single parameter signature into a FlagDefinition.
|
|
28
22
|
*
|
|
29
23
|
* Signature syntax:
|
|
30
24
|
* - {arg} -> required string argument
|
|
@@ -32,9 +26,12 @@ export declare class CommandSignatureParser<Opts extends OptionsSchema = Options
|
|
|
32
26
|
* - {arg=default} -> argument with default value
|
|
33
27
|
* - {arg*} -> variadic argument (array)
|
|
34
28
|
* - {arg:desc} -> argument with description
|
|
35
|
-
* - {--opt} -> boolean
|
|
36
|
-
* - {--opt=} -> string
|
|
37
|
-
* - {--opt
|
|
29
|
+
* - {--opt} -> boolean flag
|
|
30
|
+
* - {--opt=} -> string flag
|
|
31
|
+
* - {--opt=default} -> string flag with default
|
|
32
|
+
* - {--opt=*} -> array flag
|
|
33
|
+
* - {--opt|o} -> flag with alias
|
|
34
|
+
* - {--opt=true} -> boolean flag with default true
|
|
38
35
|
*/
|
|
39
36
|
private static parseParamSignature;
|
|
40
37
|
}
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
import { Command,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
get command(): string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}): CommandSignatureParser<Opts, Args>;
|
|
18
|
-
constructor();
|
|
19
|
-
protected abstract handle(ctx: C, opts: CommandHandlerOptions<Opts, Args>): Promise<number | void>;
|
|
1
|
+
import { Command, CommandRunOption } from './Command.js';
|
|
2
|
+
import { ContextDefinition } from './lib/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use `Command` with explicit `flags` and `args` instead. This class will be removed in a future major release.
|
|
5
|
+
*
|
|
6
|
+
* CommandWithSignature allows defining a command using a concise signature string, which is parsed to generate flags and arguments.
|
|
7
|
+
* The signature is parsed lazily on first run to avoid unnecessary overhead if the command is never executed.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class CommandWithSignature<C extends ContextDefinition = ContextDefinition> extends Command<C> {
|
|
10
|
+
static signature: string;
|
|
11
|
+
static helperDefinitions: Record<string, string>;
|
|
12
|
+
static get command(): string;
|
|
13
|
+
run(runOpts: CommandRunOption<C>): Promise<number | void>;
|
|
14
|
+
/**
|
|
15
|
+
* Convenience accessor for a parsed option value.
|
|
16
|
+
*/
|
|
20
17
|
protected option<T = string>(key: string): T | null;
|
|
21
18
|
protected option<T = string>(key: string, defaultValue: T): NoInfer<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Convenience accessor for a parsed argument value.
|
|
21
|
+
*/
|
|
22
22
|
protected argument<T = string>(key: string): T | null;
|
|
23
23
|
protected argument<T = string>(key: string, defaultValue: T): NoInfer<T>;
|
|
24
|
-
askForConfirmation(...opts: Parameters<typeof this.io.askForConfirmation>): ReturnType<typeof this.io.askForConfirmation>;
|
|
25
|
-
askForInput(...opts: Parameters<typeof this.io.askForInput>): ReturnType<typeof this.io.askForInput>;
|
|
26
|
-
askForSelect(...opts: Parameters<typeof this.io.askForSelect>): ReturnType<typeof this.io.askForSelect>;
|
|
27
|
-
newLoader(...opts: Parameters<typeof this.io.newLoader>): ReturnType<typeof this.io.newLoader>;
|
|
28
24
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BooleanFlagDef, CustomFlagDef, DirectoryFlagDef, EnumFlagDef, FileFlagDef, FlagInput, NumberFlagDef, StringFlagDef, UrlFlagDef } from './lib/types.js';
|
|
2
|
+
export declare const Flags: {
|
|
3
|
+
string<const T extends FlagInput<StringFlagDef>>(opts?: T): StringFlagDef & T;
|
|
4
|
+
number<const T extends FlagInput<NumberFlagDef>>(opts?: T): NumberFlagDef & T;
|
|
5
|
+
boolean<const T extends FlagInput<BooleanFlagDef>>(opts?: T): BooleanFlagDef & T;
|
|
6
|
+
enum<const T extends readonly string[], const U extends FlagInput<EnumFlagDef<T>, "options">>(opts: {
|
|
7
|
+
options: T;
|
|
8
|
+
} & U): EnumFlagDef<T> & U;
|
|
9
|
+
file<const T extends FlagInput<FileFlagDef>>(opts?: T): FileFlagDef & T;
|
|
10
|
+
directory<const T extends FlagInput<DirectoryFlagDef>>(opts?: T): DirectoryFlagDef & T;
|
|
11
|
+
url<const T extends FlagInput<UrlFlagDef>>(opts?: T): UrlFlagDef & T;
|
|
12
|
+
custom<T>(defaults?: FlagInput<CustomFlagDef<T>>): <const U extends FlagInput<CustomFlagDef<T>>>(overrides?: U) => CustomFlagDef<T> & U;
|
|
13
|
+
};
|
|
14
|
+
export declare const Args: {
|
|
15
|
+
string<const T extends FlagInput<StringFlagDef>>(opts?: T): StringFlagDef & T;
|
|
16
|
+
number<const T extends FlagInput<NumberFlagDef>>(opts?: T): NumberFlagDef & T;
|
|
17
|
+
boolean<const T extends FlagInput<BooleanFlagDef>>(opts?: T): BooleanFlagDef & T;
|
|
18
|
+
enum<const T extends readonly string[], const U extends FlagInput<EnumFlagDef<T>, "options">>(opts: {
|
|
19
|
+
options: T;
|
|
20
|
+
} & U): EnumFlagDef<T> & U;
|
|
21
|
+
file<const T extends FlagInput<FileFlagDef>>(opts?: T): FileFlagDef & T;
|
|
22
|
+
directory<const T extends FlagInput<DirectoryFlagDef>>(opts?: T): DirectoryFlagDef & T;
|
|
23
|
+
url<const T extends FlagInput<UrlFlagDef>>(opts?: T): UrlFlagDef & T;
|
|
24
|
+
custom<T>(defaults?: FlagInput<CustomFlagDef<T>>): <const U extends FlagInput<CustomFlagDef<T>>>(overrides?: U) => CustomFlagDef<T> & U;
|
|
25
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger } from '../Logger.js';
|
|
2
|
+
import { BobError } from './BobError.js';
|
|
3
|
+
import { FlagDefinition } from '../lib/types.js';
|
|
4
|
+
export type ArgumentProps = {
|
|
5
|
+
arg: string;
|
|
6
|
+
value?: any;
|
|
7
|
+
reason?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class BadCommandArgument extends BobError {
|
|
10
|
+
readonly detail: ArgumentProps;
|
|
11
|
+
readonly argDefinition?: FlagDefinition | undefined;
|
|
12
|
+
constructor(detail: ArgumentProps, argDefinition?: FlagDefinition | undefined);
|
|
13
|
+
pretty(logger: Logger): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger } from '../Logger.js';
|
|
2
|
+
import { BobError } from './BobError.js';
|
|
3
|
+
import { FlagDefinition } from '../lib/types.js';
|
|
4
|
+
export type FlagProps = {
|
|
5
|
+
flag: string;
|
|
6
|
+
value?: any;
|
|
7
|
+
reason?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class BadCommandFlag extends BobError {
|
|
10
|
+
readonly param: FlagProps;
|
|
11
|
+
readonly flagDefinition?: FlagDefinition | undefined;
|
|
12
|
+
constructor(param: FlagProps, flagDefinition?: FlagDefinition | undefined);
|
|
13
|
+
pretty(logger: Logger): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Logger } from '../Logger.js';
|
|
2
|
+
import { BobError } from './BobError.js';
|
|
3
|
+
import { FlagsSchema } from '../lib/types.js';
|
|
4
|
+
export declare class InvalidFlag extends BobError {
|
|
5
|
+
private flag;
|
|
6
|
+
private flagsSchema;
|
|
7
|
+
constructor(flag: string, flagsSchema?: FlagsSchema);
|
|
8
|
+
pretty(logger: Logger): void;
|
|
9
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './BobError.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './BadCommandArgument.js';
|
|
3
|
+
export * from './BadCommandFlag.js';
|
|
4
|
+
export * from './InvalidFlag.js';
|
|
5
5
|
export * from './CommandNotFoundError.js';
|
|
6
6
|
export * from './MissingRequiredArgumentValue.js';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './MissingRequiredFlagValue.js';
|
|
8
8
|
export * from './TooManyArguments.js';
|
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export * from './Command.js';
|
|
2
|
-
export * from './CommandWithSignature.js';
|
|
3
2
|
export * from './CommandIO.js';
|
|
4
3
|
export * from './CommandParser.js';
|
|
5
|
-
export * from './CommandSignatureParser.js';
|
|
6
4
|
export * from './CommandRegistry.js';
|
|
5
|
+
export * from './CommandSignatureParser.js';
|
|
6
|
+
export * from './CommandWithSignature.js';
|
|
7
7
|
export * from './Cli.js';
|
|
8
8
|
export * from './Logger.js';
|
|
9
9
|
export * from './ExceptionHandler.js';
|
|
10
10
|
export * from './StringSimilarity.js';
|
|
11
11
|
export * from './lib/types.js';
|
|
12
|
+
export * from './Flags.js';
|
|
12
13
|
export * from './errors/index.js';
|
|
13
14
|
export * from './options/index.js';
|
|
14
15
|
export * from './contracts/index.js';
|