alepha 0.9.4 → 0.10.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/command.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Alepha, AlephaError, Async, Descriptor, KIND, Static, TObject, TSchema
3
3
  import * as fs from "node:fs/promises";
4
4
  import { glob } from "node:fs/promises";
5
5
  import * as _alepha_logger0 from "alepha/logger";
6
- import * as _sinclair_typebox0 from "@sinclair/typebox";
6
+ import * as typebox0 from "typebox";
7
7
 
8
8
  //#region src/helpers/Runner.d.ts
9
9
  type Task = {
@@ -59,14 +59,14 @@ declare class Runner {
59
59
  * within your Alepha application structure.
60
60
  */
61
61
  declare const $command: {
62
- <T extends TObject>(options: CommandDescriptorOptions<T>): CommandDescriptor<T>;
62
+ <T extends TObject, A extends TSchema>(options: CommandDescriptorOptions<T, A>): CommandDescriptor<T, A>;
63
63
  [KIND]: typeof CommandDescriptor;
64
64
  };
65
- interface CommandDescriptorOptions<T extends TObject> {
65
+ interface CommandDescriptorOptions<T extends TObject, A extends TSchema> {
66
66
  /**
67
67
  * The handler function to execute when the command is matched.
68
68
  */
69
- handler: (args: CommandHandlerArgs<T>) => Async<void>;
69
+ handler: (args: CommandHandlerArgs<T, A>) => Async<void>;
70
70
  /**
71
71
  * The name of the command. If omitted, the property key is used.
72
72
  *
@@ -85,18 +85,36 @@ interface CommandDescriptorOptions<T extends TObject> {
85
85
  * A TypeBox object schema defining the flags for the command.
86
86
  */
87
87
  flags?: T;
88
+ /**
89
+ * An optional TypeBox schema defining the arguments for the command.
90
+ *
91
+ * @example
92
+ * args: t.string()
93
+ * my-cli command <arg1: string>
94
+ *
95
+ * args: t.optional(t.string())
96
+ * my-cli command [arg1: string]
97
+ *
98
+ * args: t.tuple([t.string(), t.number()])
99
+ * my-cli command <arg1: string> <arg2: number>
100
+ *
101
+ * args: t.tuple([t.string(), t.optional(t.number())])
102
+ * my-cli command <arg1: string> [arg2: number]
103
+ */
104
+ args?: A;
88
105
  /**
89
106
  * If false, skip summary message at the end of the command execution.
90
107
  */
91
108
  summary?: boolean;
92
109
  }
93
- declare class CommandDescriptor<T extends TObject = TObject> extends Descriptor<CommandDescriptorOptions<T>> {
110
+ declare class CommandDescriptor<T extends TObject = TObject, A extends TSchema = TSchema> extends Descriptor<CommandDescriptorOptions<T, A>> {
94
111
  readonly flags: TObject<{}>;
95
112
  readonly aliases: string[];
96
113
  get name(): string;
97
114
  }
98
- interface CommandHandlerArgs<T extends TObject> {
115
+ interface CommandHandlerArgs<T extends TObject, A extends TSchema = TSchema> {
99
116
  flags: Static<T>;
117
+ args: A extends TSchema ? Static<A> : undefined;
100
118
  run: RunnerMethod;
101
119
  glob: typeof glob;
102
120
  fs: typeof fs;
@@ -132,7 +150,7 @@ declare class CliProvider {
132
150
  help: {
133
151
  aliases: string[];
134
152
  description: string;
135
- schema: _sinclair_typebox0.TBoolean;
153
+ schema: typebox0.TBoolean;
136
154
  };
137
155
  };
138
156
  protected readonly onReady: _alepha_core1.HookDescriptor<"ready">;
@@ -144,6 +162,10 @@ declare class CliProvider {
144
162
  aliases: string[];
145
163
  schema: TSchema;
146
164
  }[]): Record<string, any>;
165
+ protected parseCommandArgs(argv: string[], schema?: TSchema): any;
166
+ protected parseArgumentValue(value: string, schema: TSchema): any;
167
+ protected generateArgsUsage(schema?: TSchema): string;
168
+ protected getTypeName(schema: TSchema): string;
147
169
  printHelp(command?: CommandDescriptor<any>): void;
148
170
  private getMaxCmdLength;
149
171
  private getMaxFlagLength;
@@ -160,7 +182,7 @@ declare class CliProvider {
160
182
  * @module alepha.command
161
183
  */
162
184
  declare const AlephaCommand: _alepha_core1.Service<_alepha_core1.Module>;
163
- declare module "@sinclair/typebox" {
185
+ declare module "typebox" {
164
186
  interface StringOptions {
165
187
  /**
166
188
  * Additional aliases for the flags.
@@ -170,6 +192,8 @@ declare module "@sinclair/typebox" {
170
192
  aliases?: string[];
171
193
  }
172
194
  }
195
+ //# sourceMappingURL=index.d.ts.map
196
+
173
197
  //#endregion
174
198
  export { $command, AlephaCommand, CliProvider, CommandDescriptor, CommandDescriptorOptions, CommandError, CommandHandlerArgs, RunOptions, Runner, RunnerMethod, Task };
175
199
  //# sourceMappingURL=index.d.ts.map