gunshi 0.2.0 → 0.2.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/types.d.ts DELETED
@@ -1,302 +0,0 @@
1
- import type { ArgOptions, ArgValues } from "args-tokens";
2
- /**
3
- * Define a promise type that can be await from T
4
- */
5
- type Awaitable<T> = T | Promise<T>;
6
- /**
7
- * The command i18n built-in options keys
8
- * @experimental
9
- */
10
- export type CommandBuiltinOptionsKeys = keyof (typeof import("./constants"))["COMMON_OPTIONS"];
11
- /**
12
- * The command i18n built-in resource keys
13
- * @experimental
14
- */
15
- export type CommandBuiltinResourceKeys = (typeof import("./constants"))["COMMAND_I18N_RESOURCE_KEYS"][number];
16
- /**
17
- * The command i18n built-in keys
18
- * @description The command i18n built-in keys are used to {@link CommandContext.translation | translate} function
19
- * @experimental
20
- */
21
- export type CommandBuiltinKeys = CommandBuiltinOptionsKeys | CommandBuiltinResourceKeys | "description" | "examples";
22
- /**
23
- * The command environment
24
- */
25
- export interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
26
- /**
27
- * The current working directory
28
- * @see {@link CommandOptions.cwd}
29
- */
30
- cwd: string | undefined;
31
- /**
32
- * The command name
33
- * @see {@link CommandOptions.name}
34
- */
35
- name: string | undefined;
36
- /**
37
- * The command description
38
- * @see {@link CommandOptions.description}
39
- *
40
- */
41
- description: string | undefined;
42
- /**
43
- * The command version
44
- * @see {@link CommandOptions.version}
45
- */
46
- version: string | undefined;
47
- /**
48
- * The left margin of the command output
49
- * @default 2
50
- * @see {@link CommandOptions.leftMargin}
51
- */
52
- leftMargin: number;
53
- /**
54
- * The middle margin of the command output
55
- * @default 10
56
- * @see {@link CommandOptions.middleMargin}
57
- */
58
- middleMargin: number;
59
- /**
60
- * Whether to display the usage option type
61
- * @default false
62
- * @see {@link CommandOptions.usageOptionType}
63
- */
64
- usageOptionType: boolean;
65
- /**
66
- * The sub commands
67
- * @see {@link CommandOptions.subCommands}
68
- */
69
- subCommands: Map<string, Command<Options> | LazyCommand<Options>> | undefined;
70
- /**
71
- * Render function the command usage
72
- */
73
- renderUsage: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
74
- /**
75
- * Render function the header section in the command usage
76
- */
77
- renderHeader: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
78
- /**
79
- * Render function the validation errors
80
- */
81
- renderValidationErrors: ((ctx: CommandContext<Options>, error: AggregateError) => Promise<string>) | null | undefined;
82
- }
83
- /**
84
- * The command options
85
- */
86
- export interface CommandOptions<Options extends ArgOptions> {
87
- /**
88
- * The current working directory
89
- * @description This is the current working directory path passed in the context of the run command. This is useful if you need your command about the current execution directory.
90
- */
91
- cwd?: string;
92
- /**
93
- * The command name
94
- * @description Please specify the name of the command that was executed. If you would specify it, gunshi will be displayed in the usage.
95
- */
96
- name?: string;
97
- /**
98
- * The command description
99
- * @description Please specify the description (summary) of the command that was executed. If you would specify it, gunshi will be displayed in the usage.
100
- *
101
- */
102
- description?: string;
103
- /**
104
- * The command version
105
- * @description Please specify the version of the command that was executed. If you would specify it, gunshi will be displayed in the usage.
106
- */
107
- version?: string;
108
- /**
109
- * The locale of the command
110
- * @description The locale of the command that was executed. If you would specify it, gunshi command usage will be localized.
111
- */
112
- locale?: string | Intl.Locale;
113
- /**
114
- * The sub commands
115
- */
116
- subCommands?: Map<string, Command<Options> | LazyCommand<Options>>;
117
- /**
118
- * The left margin of the command output
119
- */
120
- leftMargin?: number;
121
- /**
122
- * The middle margin of the command output
123
- */
124
- middleMargin?: number;
125
- /**
126
- * Whether to display the usage option type
127
- */
128
- usageOptionType?: boolean;
129
- /**
130
- * Render function the command usage
131
- */
132
- renderUsage?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
133
- /**
134
- * Render function the header section in the command usage
135
- */
136
- renderHeader?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
137
- /**
138
- * Render function the validation errors
139
- */
140
- renderValidationErrors?: ((ctx: Readonly<CommandContext<Options>>, error: AggregateError) => Promise<string>) | null;
141
- }
142
- /**
143
- * The command context
144
- * @description The command context is the context of the command execution
145
- */
146
- export interface CommandContext<
147
- Options extends ArgOptions,
148
- Values = ArgValues<Options>
149
- > {
150
- /**
151
- * The command name, that is the command that is executed
152
- * @description The command name is same {@link CommandEnvironment.name}
153
- */
154
- name: string | undefined;
155
- /**
156
- * The command description, that is the description of the command that is executed
157
- * @description The command description is same {@link CommandEnvironment.description}
158
- */
159
- description: string | undefined;
160
- /**
161
- * The command locale, that is the locale of the command that is executed
162
- */
163
- locale: Intl.Locale;
164
- /**
165
- * The command environment, that is the environment of the command that is executed
166
- * @description The command environment is same {@link CommandEnvironment}
167
- */
168
- env: CommandEnvironment<Options>;
169
- /**
170
- * The command options, that is the options of the command that is executed
171
- * @description The command options is same {@link Command.options}
172
- */
173
- options: Options | undefined;
174
- /**
175
- * The command values, that is the values of the command that is executed
176
- * @description Resolve values with `resolveArgs` from command arguments and {@link Command.options}
177
- */
178
- values: Values;
179
- /**
180
- * The command positionals, that is the positionals of the command that is executed
181
- * @description Resolve positionals with `resolveArgs` from command arguments
182
- */
183
- positionals: string[];
184
- /**
185
- * Whether the currently executing command has been executed with the sub-command name omitted
186
- */
187
- omitted: boolean;
188
- /**
189
- * The usage of the command
190
- * @description The usage of the command is same {@link Command.usage}, and more has `--help` and `--version` options
191
- */
192
- usage: CommandUsage<Options>;
193
- /**
194
- * Load the sub-commands
195
- * @description The loaded commands are cached and returned when called again
196
- * @returns loaded commands
197
- */
198
- loadCommands: () => Promise<Command<Options>[]>;
199
- /**
200
- * The translation function
201
- * @param key {CommandBuiltinKeys | T} - The key to be translated
202
- * @returns The translated string, if the key is not found, the key itself is returned
203
- * @experimental
204
- */
205
- translation: <
206
- T = CommandBuiltinKeys,
207
- Key = CommandBuiltinKeys | T
208
- >(key: Key) => string;
209
- }
210
- /**
211
- * The command usage render
212
- * @description if the render function is async, it should return a promise
213
- */
214
- export type CommandUsageRender<Options extends ArgOptions> = ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | string;
215
- /**
216
- * The command usage
217
- */
218
- interface CommandUsage<Options extends ArgOptions> {
219
- /**
220
- * The options usage
221
- */
222
- options?: { [Option in keyof Options] : string };
223
- /**
224
- * The examples usage
225
- */
226
- examples?: string;
227
- }
228
- /**
229
- * The command interface
230
- */
231
- export interface Command<Options extends ArgOptions> {
232
- /**
233
- * The command name
234
- * @description
235
- * The command name is used to find command line arguments to execute from sub commands, so it's recommended to specify.
236
- */
237
- name?: string;
238
- /**
239
- * The command description
240
- * @description
241
- * The command description is used to describe the command in usage, so it's recommended to specify.
242
- */
243
- description?: string;
244
- /**
245
- * whether the command is default or not
246
- * @description if the command is default, it is executed when no sub-command is specified
247
- */
248
- default?: boolean;
249
- /**
250
- * The command options
251
- */
252
- options?: Options;
253
- /**
254
- * The command usage
255
- * @description
256
- * The command usage is used to describe the command in usage, so it's recommended to specify.
257
- */
258
- usage?: CommandUsage<Options>;
259
- /**
260
- * The command runner, that's the command to be executed
261
- */
262
- run: CommandRunner<Options>;
263
- /**
264
- * The command resource fetcher
265
- * @experimental
266
- */
267
- resource?: CommandResourceFetcher<Options>;
268
- }
269
- /**
270
- * The command resource
271
- * @experimental
272
- */
273
- export interface CommandResource<Options extends ArgOptions> {
274
- /**
275
- * The command description resource
276
- */
277
- description: string;
278
- /**
279
- * The options usage resources
280
- */
281
- options: { [Option in keyof Options] : string };
282
- /**
283
- * The examples usage resources
284
- */
285
- examples: string;
286
- }
287
- /**
288
- * The command resource fetcher
289
- * @experimental
290
- */
291
- export type CommandResourceFetcher<Options extends ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Promise<CommandResource<Options>>;
292
- /**
293
- * The command runner interface
294
- * @param ctx - The {@link CommandContext | command context}
295
- */
296
- export type CommandRunner<Options extends ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Awaitable<void>;
297
- /**
298
- * The lazy command interface
299
- * @description The lazy command that's not loaded until it is executed
300
- */
301
- export type LazyCommand<Options extends ArgOptions> = () => Awaitable<Command<Options>>;
302
- export {};
package/lib/utils.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { ArgOptions } from "args-tokens";
2
- import type { Command, LazyCommand } from "./types.js";
3
- export declare function resolveLazyCommand<Options extends ArgOptions>(cmd: Command<Options> | LazyCommand<Options>, name: string | undefined, entry?: boolean): Promise<Command<Options>>;
4
- export declare function create<T>(obj?: object | null): T;
5
- export declare function log(...args: unknown[]): void;
6
- export declare function deepFreeze<T extends Record<string, any>>(obj: T): Readonly<T>;