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
@@ -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';