bob-core 2.1.0 → 3.0.0-alpha.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/cjs/package-I_hjzzxG.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 +21 -25
- 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-DXx2gXIL.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 +21 -25
- 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
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 flag value.
|
|
16
|
+
*/
|
|
17
|
+
protected flag<T = string>(key: string): T | null;
|
|
18
|
+
protected flag<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/esm/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';
|