@bemoje/cli 2.0.1 → 2.0.2

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/lib/Command.d.ts CHANGED
@@ -1,125 +1,149 @@
1
- import type { CamelCase, SetFieldType, Simplify, SetRequired } from 'type-fest';
1
+ import type { ActionHandler } from './types';
2
+ import type { AllowedArgumentUsage } from './types';
3
+ import type { Argument } from './types';
4
+ import type { Arguments } from './types';
5
+ import type { BooleanOptionOptions } from './types';
6
+ import type { CamelCase } from 'type-fest';
2
7
  import { Help } from './Help';
3
- import type { Arguments, Argument, ICommand, Option, Options, SubCommands } from './types';
4
- import type { ActionHandler, BooleanOptionOptions, AllowedArgumentUsage, InferAddedArgumentType, InferAddOptionResult, OptionalArgumentOptions, OptionalArgumentOptionsWithDefaultValue, OptionalOptionOptions, OptionalVariadicArgumentOptions, OptionalVariadicOptionOptions, RequiredArgumentOptions, RequiredOptionOptions, RequiredVariadicArgumentOptions, RequiredVariadicOptionOptions, ParseArgvResult, HookDefinition, HookActionHandler } from './types';
8
+ import type { HookActionHandler } from './types';
9
+ import type { HookDefinition } from './types';
10
+ import type { ICommand } from './types';
11
+ import type { InferAddOptionResult } from './types';
12
+ import type { InferAddedArgumentType } from './types';
13
+ import type { Option } from './types';
14
+ import type { OptionalArgumentOptions } from './types';
15
+ import type { OptionalArgumentOptionsWithDefaultValue } from './types';
16
+ import type { OptionalOptionOptions } from './types';
17
+ import type { OptionalVariadicArgumentOptions } from './types';
18
+ import type { OptionalVariadicOptionOptions } from './types';
19
+ import type { Options } from './types';
20
+ import type { ParseArgvResult } from './types';
21
+ import type { RequiredArgumentOptions } from './types';
22
+ import type { RequiredOptionOptions } from './types';
23
+ import type { RequiredVariadicArgumentOptions } from './types';
24
+ import type { RequiredVariadicOptionOptions } from './types';
25
+ import type { SetFieldType } from 'type-fest';
26
+ import type { SetRequired } from 'type-fest';
27
+ import type { Simplify } from 'type-fest';
28
+ import type { SubCommands } from './types';
5
29
  /**
6
- * A type-safe CLI composer that can parse argv and generate help without execution coupling.
30
+ * a type-safe CLI composer that can parse argv and generate help without execution coupling.
7
31
  */
8
32
  export declare class Command<A extends Arguments = [], O extends Options = {
9
33
  help?: boolean;
10
34
  debug?: boolean;
11
35
  }, Subs extends SubCommands = SubCommands> implements ICommand {
12
- /** Parent command in the hierarchy, undefined for root command */
36
+ /** parent command in the hierarchy, undefined for root command */
13
37
  parent?: Command<Arguments, Options & O>;
14
- /** The command name used to invoke it */
38
+ /** the command name used to invoke it */
15
39
  name: string;
16
- /** Semantic version string displayed by --version flag */
40
+ /** semantic version string displayed by --version flag */
17
41
  version?: string;
18
- /** Alternative names for invoking this command */
42
+ /** alternative names for invoking this command */
19
43
  aliases: string[];
20
- /** Brief one-line description shown in command lists */
44
+ /** brief one-line description shown in command lists */
21
45
  summary?: string;
22
- /** Full description displayed in help text */
46
+ /** full description displayed in help text */
23
47
  description: string;
24
- /** Whether to exclude from help listings */
48
+ /** whether to exclude from help listings */
25
49
  hidden?: boolean;
26
- /** Category for organizing related commands in help output */
50
+ /** category for organizing related commands in help output */
27
51
  group?: string;
28
- /** Positional arguments this command accepts */
52
+ /** positional arguments this command accepts */
29
53
  arguments: Argument[];
30
- /** CLI options (flags) this command recognizes */
54
+ /** cLI options (flags) this command recognizes */
31
55
  options: Option[];
32
- /** Subcommands registered with this command */
56
+ /** subcommands registered with this command */
33
57
  commands: Subs;
34
- /** Main action handler executed when command is invoked */
58
+ /** main action handler executed when command is invoked */
35
59
  protected action?: ActionHandler<A, O, Subs>;
36
- /** Option-driven actions (e.g., --help, --version) executed when their conditions match */
60
+ /** option-driven actions (e.g., --help, --version) executed when their conditions match */
37
61
  protected hooks: HookDefinition<Arguments, Options & O>[];
38
62
  constructor(name: string, parent?: ICommand);
39
63
  protected get help(): Help;
40
- /** Configure how the help is rendered */
64
+ /** configure how the help is rendered */
41
65
  helpConfiguration(cb?: (help: Help) => void): this;
42
- /** Renders formatted help text using provided help definition */
66
+ /** renders formatted help text using provided help definition */
43
67
  renderHelp(config?: {
44
68
  noColor?: boolean;
45
69
  }): string;
46
- /** Sets the command name */
70
+ /** sets the command name */
47
71
  setName(name: string): void;
48
- /** Sets command aliases, flattening nested arrays */
72
+ /** sets command aliases, flattening nested arrays */
49
73
  setAliases(...aliases: (string | string[])[]): this;
50
- /** Adds aliases to existing ones */
74
+ /** adds aliases to existing ones */
51
75
  addAliases(...aliases: (string | string[])[]): this;
52
- /** Sets the command version */
76
+ /** sets the command version */
53
77
  setVersion(version: string): InferAddOptionResult<A, O, {
54
78
  version?: boolean;
55
79
  }, Subs>;
56
- /** Sets the command summary */
80
+ /** sets the command summary */
57
81
  setSummary(summary?: string): this;
58
- /** Sets command description, joining variadic lines */
82
+ /** sets command description, joining variadic lines */
59
83
  setDescription(...lines: string[]): this;
60
- /** Sets whether command is hidden from help */
84
+ /** sets whether command is hidden from help */
61
85
  setHidden(hidden?: boolean | undefined): this;
62
- /** Sets the command group for help organization */
86
+ /** sets the command group for help organization */
63
87
  setGroup(group?: string): this;
64
- /** Add a subcommand and return the subcommand. All options are inherited by the subcommand. */
88
+ /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
65
89
  command<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb?: (cmd: Command<[], O, {}>, parent: this) => Sub): Sub;
66
- /** Add a subcommand and return the subcommand. All options are inherited by the subcommand. */
90
+ /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
67
91
  addCommand<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb: (cmd: Command<[], O, {}>, parent: this) => Sub): Command<A, O, (SubCommands extends Subs ? {} : Subs) & {
68
92
  [K in Name]: Sub;
69
93
  }>;
70
- /** Add required variadic argument, eg.: `<name...>` */
94
+ /** add required variadic argument, eg.: `<name...>` */
71
95
  addArgument<const Opts extends RequiredVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}...>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
72
- /** Add required argument, eg.: `<name>` */
96
+ /** add required argument, eg.: `<name>` */
73
97
  addArgument<const Opts extends RequiredArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
74
- /** Add optional variadic argument with defaults, eg.: `[name...]` */
98
+ /** add optional variadic argument with defaults, eg.: `[name...]` */
75
99
  addArgument<const Opts extends OptionalVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}...]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
76
- /** Add optional argument with default, eg.: `[name]` */
100
+ /** add optional argument with default, eg.: `[name]` */
77
101
  addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(usage: AllowedArgumentUsage<this, `[${string}]`>, options: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
78
- /** Add optional argument, eg.: `[name]` */
102
+ /** add optional argument, eg.: `[name]` */
79
103
  addArgument<const Opts extends OptionalArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
80
- /** Add optional string option, eg.: `-o, --output [path]` */
104
+ /** add optional string option, eg.: `-o, --output [path]` */
81
105
  addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
82
106
  [K in CamelCase<Long>]?: string;
83
107
  } & O>, Subs>;
84
- /** Add optional string option with default, eg.: `-o, --output [path]` */
108
+ /** add optional string option with default, eg.: `-o, --output [path]` */
85
109
  addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>): Command<A, Simplify<{
86
110
  [K in CamelCase<Long>]: string;
87
111
  } & O>, Subs>;
88
- /** Add required variadic option, eg.: `-i, --include <patterns...>` */
112
+ /** add required variadic option, eg.: `-i, --include <patterns...>` */
89
113
  addOption<Long extends string>(flags: `-${string}, --${Long} <${string}...>`, options?: RequiredVariadicOptionOptions): Command<A, Simplify<{
90
114
  [K in CamelCase<Long>]: string[];
91
115
  } & O>, Subs>;
92
- /** Add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
116
+ /** add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
93
117
  addOption<Long extends string>(flags: `-${string}, --${Long} [${string}...]`, options?: OptionalVariadicOptionOptions): Command<A, Simplify<{
94
118
  [K in CamelCase<Long>]: string[];
95
119
  } & O>, Subs>;
96
- /** Add required string option, eg.: `-f, --file <path>` */
120
+ /** add required string option, eg.: `-f, --file <path>` */
97
121
  addOption<Long extends string>(flags: `-${string}, --${Long} <${string}>`, options?: RequiredOptionOptions): Command<A, Simplify<{
98
122
  [K in CamelCase<Long>]: string;
99
123
  } & O>, Subs>;
100
- /** Add boolean flag option with default, eg.: `-v, --verbose` */
124
+ /** add boolean flag option with default, eg.: `-v, --verbose` */
101
125
  addOption<Long extends string>(flags: `-${string}, --${Long}`, options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>): Command<A, Simplify<{
102
126
  [K in CamelCase<Long>]: boolean;
103
127
  } & O>, Subs>;
104
- /** Add boolean flag option, eg.: `-v, --verbose` */
128
+ /** add boolean flag option, eg.: `-v, --verbose` */
105
129
  addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
106
130
  [K in CamelCase<Long>]?: boolean;
107
131
  } & O>, Subs>;
108
132
  /**
109
- * Register an action to be invoked when an option is set to true or string value.
133
+ * register an action to be invoked when an option is set to true or string value.
110
134
  *
111
135
  * Hooks execute in addition to or instead of the main action handler,
112
136
  * allowing for option-driven behavior. For example, `--help` and `--version`
113
137
  * are implemented as hooks.
114
138
  */
115
139
  addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
116
- /** Parses command-line arguments with subcommand support and type-safe validation. */
140
+ /** parses command-line arguments with subcommand support and type-safe validation. */
117
141
  parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
118
142
  /**
119
- * Sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
143
+ * sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
120
144
  * The handler receives parsed arguments and options with correct typings.
121
145
  */
122
146
  setAction(fn: ActionHandler<A, O, Subs>): this;
123
- /** Returns a new Command instance. Override this method in subclasses. */
147
+ /** returns a new Command instance. Override this method in subclasses. */
124
148
  protected createSubcommand(name: string): Command<[], O, {}>;
125
149
  }
package/lib/Help.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { IHelp, Argument, ICommand, Option } from './types';
1
+ import type { Argument } from './types';
2
+ import type { ICommand } from './types';
3
+ import type { IHelp } from './types';
4
+ import type { Option } from './types';
2
5
  /**
3
6
  * This is a fork of the Help class from the 'commander' npm package. The Help class method names as well as the
4
7
  * expected interface of the Command instance to parse, are both similar, but different and not compatible without
@@ -1,4 +1,5 @@
1
- import type { ICommand, Option } from '../types';
1
+ import type { ICommand } from '../types';
2
+ import type { Option } from '../types';
2
3
  /**
3
4
  * Finds option by name, short name or long name
4
5
  */
@@ -1,3 +1,4 @@
1
- import type { Argument, Option } from '../types';
1
+ import type { Argument } from '../types';
2
+ import type { Option } from '../types';
2
3
  /** Validate parsed arguments and option values, returning errors or undefined */
3
4
  export declare function validateParsed(args: unknown[], optionValues: Record<string, unknown>, argDefs: Argument[], optionDefs: Option[]): string[] | undefined;
package/lib/types.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import type { AllUnionFields } from 'type-fest';
1
2
  import type { Command } from './Command';
2
- import type { Simplify, AllUnionFields, SetFieldType, SetRequired } from 'type-fest';
3
+ import type { SetFieldType } from 'type-fest';
4
+ import type { SetRequired } from 'type-fest';
5
+ import type { Simplify } from 'type-fest';
3
6
  /** Logger interface defining methods for different log levels. */
4
7
  export interface Logger {
5
8
  start: (...args: unknown[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A type-safe CLI composer that can parse argv and generate help without execution coupling.",
5
5
  "type": "module",
6
6
  "sideEffects": false,