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.
Files changed (57) hide show
  1. package/dist/cjs/package-I_hjzzxG.cjs +1 -0
  2. package/dist/cjs/src/Cli.d.ts +4 -6
  3. package/dist/cjs/src/Command.d.ts +27 -50
  4. package/dist/cjs/src/CommandParser.d.ts +48 -50
  5. package/dist/cjs/src/CommandRegistry.d.ts +5 -5
  6. package/dist/cjs/src/CommandSignatureParser.d.ts +22 -25
  7. package/dist/cjs/src/CommandWithSignature.d.ts +21 -25
  8. package/dist/cjs/src/Flags.d.ts +25 -0
  9. package/dist/cjs/src/commands/HelpCommand.d.ts +2 -0
  10. package/dist/cjs/src/contracts/index.d.ts +0 -1
  11. package/dist/cjs/src/errors/BadCommandArgument.d.ts +14 -0
  12. package/dist/cjs/src/errors/BadCommandFlag.d.ts +14 -0
  13. package/dist/cjs/src/errors/InvalidFlag.d.ts +9 -0
  14. package/dist/cjs/src/errors/MissingRequiredFlagValue.d.ts +7 -0
  15. package/dist/cjs/src/errors/index.d.ts +4 -4
  16. package/dist/cjs/src/index.d.ts +3 -2
  17. package/dist/cjs/src/index.js +5 -14
  18. package/dist/cjs/src/lib/helpers.d.ts +1 -0
  19. package/dist/cjs/src/lib/types.d.ts +72 -18
  20. package/dist/cjs/src/options/HelpOption.d.ts +11 -10
  21. package/dist/esm/package-DXx2gXIL.js +59 -0
  22. package/dist/esm/src/Cli.d.ts +4 -6
  23. package/dist/esm/src/Command.d.ts +27 -50
  24. package/dist/esm/src/CommandParser.d.ts +48 -50
  25. package/dist/esm/src/CommandRegistry.d.ts +5 -5
  26. package/dist/esm/src/CommandSignatureParser.d.ts +22 -25
  27. package/dist/esm/src/CommandWithSignature.d.ts +21 -25
  28. package/dist/esm/src/Flags.d.ts +25 -0
  29. package/dist/esm/src/commands/HelpCommand.d.ts +2 -0
  30. package/dist/esm/src/contracts/index.d.ts +0 -1
  31. package/dist/esm/src/errors/BadCommandArgument.d.ts +14 -0
  32. package/dist/esm/src/errors/BadCommandFlag.d.ts +14 -0
  33. package/dist/esm/src/errors/InvalidFlag.d.ts +9 -0
  34. package/dist/esm/src/errors/MissingRequiredFlagValue.d.ts +7 -0
  35. package/dist/esm/src/errors/index.d.ts +4 -4
  36. package/dist/esm/src/index.d.ts +3 -2
  37. package/dist/esm/src/index.js +926 -1070
  38. package/dist/esm/src/lib/helpers.d.ts +1 -0
  39. package/dist/esm/src/lib/types.d.ts +72 -18
  40. package/dist/esm/src/options/HelpOption.d.ts +11 -10
  41. package/package.json +11 -12
  42. package/dist/cjs/package-DYSfqWOt.cjs +0 -1
  43. package/dist/cjs/src/contracts/CommandOption.d.ts +0 -6
  44. package/dist/cjs/src/errors/BadCommandOption.d.ts +0 -12
  45. package/dist/cjs/src/errors/BadCommandParameter.d.ts +0 -12
  46. package/dist/cjs/src/errors/InvalidOption.d.ts +0 -9
  47. package/dist/cjs/src/errors/MissingRequiredOptionValue.d.ts +0 -7
  48. package/dist/cjs/src/lib/optionHelpers.d.ts +0 -5
  49. package/dist/cjs/src/lib/valueConverter.d.ts +0 -10
  50. package/dist/esm/package-uVOgoItG.js +0 -33
  51. package/dist/esm/src/contracts/CommandOption.d.ts +0 -6
  52. package/dist/esm/src/errors/BadCommandOption.d.ts +0 -12
  53. package/dist/esm/src/errors/BadCommandParameter.d.ts +0 -12
  54. package/dist/esm/src/errors/InvalidOption.d.ts +0 -9
  55. package/dist/esm/src/errors/MissingRequiredOptionValue.d.ts +0 -7
  56. package/dist/esm/src/lib/optionHelpers.d.ts +0 -5
  57. package/dist/esm/src/lib/valueConverter.d.ts +0 -10
@@ -0,0 +1 @@
1
+ var e={name:`bob-core`,version:`3.0.0-alpha.0`,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;
@@ -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, OptionsSchema } from './lib/types.js';
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, OptionsSchema, OptionsSchema> | {
28
- new (): Command<C>;
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, OptionsSchema, OptionsSchema>): void;
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 { CommandOption } from './contracts/index.js';
5
- import { ArgumentsObject, ArgumentsSchema, ContextDefinition, OptionsObject, OptionsSchema } from './lib/types.js';
6
- export type CommandHandlerOptions<Options extends OptionsSchema, Arguments extends ArgumentsSchema> = {
7
- options: OptionsObject<Options>;
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 CommandHandler<C extends ContextDefinition, Options extends OptionsSchema, Arguments extends ArgumentsSchema> = (ctx: C, opts: CommandHandlerOptions<Options, Arguments>) => Promise<number | void> | number | void;
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
- options: OptionsObject<Options>;
18
- arguments: ArgumentsObject<Arguments>;
15
+ args: Record<string, any>;
16
+ flags: Record<string, any>;
19
17
  });
20
- export type CommandExample = {
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
- readonly _command: string;
27
- readonly description: string;
28
- readonly group?: string;
29
- protected commandsExamples: CommandExample[];
30
- get command(): string;
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<Options, Arguments>;
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 _preHandler?: CommandHandler<C, Options, Arguments>;
41
- protected handle?(ctx: C, opts: CommandHandlerOptions<Options, Arguments>): Promise<number | void> | number | void;
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
- options: Options;
48
- arguments: Arguments;
49
- }): CommandParser<Options, Arguments>;
42
+ }): CommandParser<FlagsSchema, FlagsSchema>;
50
43
  protected newCommandIO(opts: CommandIOOptions): CommandIO;
51
- constructor(command: string, opts?: {
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 { OptionDetails } from './lib/optionHelpers.js';
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 options and arguments
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<Options extends OptionsSchema, Arguments extends OptionsSchema> {
9
- protected options: Options;
10
- protected parsedOptions: OptionsObject<Options> | null;
11
- protected arguments: Arguments;
12
- protected parsedArguments: OptionsObject<Arguments> | null;
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 shouldPromptForMissingOptions: boolean;
15
- protected shouldValidateUnknownOptions: boolean;
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 options and arguments
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 options and arguments
26
- * @throws {InvalidOption} If an naan option is provided
27
- * @throws {BadCommandOption} If a value cannot be converted to the expected type
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
- options: OptionsObject<Options>;
31
- arguments: OptionsObject<Arguments>;
32
- };
35
+ init(args: string[]): Promise<{
36
+ flags: FlagsObject<Flags>;
37
+ args: FlagsObject<Arguments>;
38
+ }>;
33
39
  /**
34
- * Validates the parsed options and arguments
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 option value by name
40
- * @param name - The option name
41
- * @param defaultValue - Optional default value if option is not set
42
- * @returns The typed option value
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
- option<OptsName extends keyof Options>(name: OptsName, defaultValue?: OptionReturnType<Options[OptsName]>): OptionReturnType<Options[OptsName]>;
46
- setOption<OptsName extends keyof Options>(name: OptsName, value: OptionReturnType<Options[OptsName]>): void;
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?: OptionReturnType<Arguments[ArgName]>): OptionReturnType<Arguments[ArgName]>;
55
- setArgument<ArgName extends keyof Arguments>(name: ArgName, value: OptionReturnType<Arguments[ArgName]>): void;
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 options are recognized
64
- * @throws {InvalidOption} If an unknown option is found
69
+ * Validates that all provided flags are recognized
70
+ * @throws {InvalidFlag} If an unknown flag is found
65
71
  */
66
- private validateUnknownOptions;
72
+ private validateUnknownFlags;
67
73
  /**
68
- * Processes named options from minimist output
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
- * Handles variadic arguments that consume all remaining positional values
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 resolveArgumentValue;
85
+ private resolveFlagValue;
84
86
  /**
85
- * Resolves an option value from the parsed option values object
86
- * Handles alias resolution, defaults, and type conversion
87
+ * Parses a raw value using the flag's parse function
87
88
  */
88
- private resolveOptionValue;
89
- optionDefinitions(): Record<string, OptionDetails>;
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
- allowUnknownOptions(): this;
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 argDef - The argument's definition for type and description
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, argDef: OptionDefinition): Promise<string | number | string[] | null>;
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 { ArgumentsSchema, ContextDefinition, OptionsSchema } from './lib/types.js';
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<C extends ContextDefinition = ContextDefinition, Opts extends OptionsSchema = OptionsSchema, Args extends ArgumentsSchema = ArgumentsSchema>(command: Command<C, Opts, Args>, force?: boolean): void;
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 { Command } from './Command.js';
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
- * Extends CommandParser to parse command signatures like "command {arg} {--option}"
8
- * Handles interactive prompting for missing required arguments via CommandIO
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<Opts extends OptionsSchema = OptionsSchema, Args extends OptionsSchema = OptionsSchema> extends CommandParser<Opts, Args> {
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 parameter schemas
22
- * Example: "migrate {name} {--force}" -> { command: "migrate", arguments: {name: ...}, options: {force: ...} }
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
- private static parseSignature;
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 like "{name}" or "{--force}" or "{files*}"
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 option
36
- * - {--opt=} -> string option
37
- * - {--opt|o} -> option with alias
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, CommandHandlerOptions } from './Command.js';
2
- import { CommandIO } from './CommandIO.js';
3
- import { CommandSignatureParser } from './CommandSignatureParser.js';
4
- import { ContextDefinition, OptionsSchema } from './lib/types.js';
5
- export declare abstract class CommandWithSignature<C extends ContextDefinition = ContextDefinition, Opts extends OptionsSchema = OptionsSchema, Args extends OptionsSchema = OptionsSchema> extends Command<C, Opts, Args> {
6
- abstract signature: string;
7
- abstract description: string;
8
- protected helperDefinitions: {
9
- [key: string]: string;
10
- };
11
- protected parser: CommandSignatureParser<Opts, Args>;
12
- get command(): string;
13
- protected newCommandParser(opts: {
14
- io: CommandIO;
15
- options: Opts;
16
- arguments: Args;
17
- }): CommandSignatureParser<Opts, Args>;
18
- constructor();
19
- protected abstract handle(ctx: C, opts: CommandHandlerOptions<Opts, Args>): Promise<number | void>;
20
- protected option<T = string>(key: string): T | null;
21
- protected option<T = string>(key: string, defaultValue: T): NoInfer<T>;
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
+ };
@@ -7,6 +7,8 @@ export type HelpCommandOptions = {
7
7
  };
8
8
  export default class HelpCommand extends Command {
9
9
  private opts;
10
+ static command: string;
11
+ static description: string;
10
12
  constructor(opts: HelpCommandOptions);
11
13
  handle(): Promise<void>;
12
14
  }
@@ -1,2 +1 @@
1
- export * from './CommandOption.js';
2
1
  export * from './LoggerContract.js';
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ import { Logger } from '../Logger.js';
2
+ import { BobError } from './BobError.js';
3
+ export declare class MissingRequiredFlagValue extends BobError {
4
+ readonly flag: string;
5
+ constructor(flag: string);
6
+ pretty(logger: Logger): void;
7
+ }
@@ -1,8 +1,8 @@
1
1
  export * from './BobError.js';
2
- export * from './BadCommandParameter.js';
3
- export * from './BadCommandOption.js';
4
- export * from './InvalidOption.js';
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 './MissingRequiredOptionValue.js';
7
+ export * from './MissingRequiredFlagValue.js';
8
8
  export * from './TooManyArguments.js';
@@ -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';