@gunshi/shared 1.0.0-beta.0 → 1.0.0-beta.1

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/index.d.ts CHANGED
@@ -55,9 +55,6 @@ interface ArgToken {
55
55
  */
56
56
  inlineValue?: boolean | undefined;
57
57
  }
58
- /**
59
- * Parser Options.
60
- */
61
58
  //#endregion
62
59
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/resolver.d.ts
63
60
  //#region src/resolver.d.ts
@@ -638,7 +635,7 @@ interface Args {
638
635
  *
639
636
  * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
640
637
  */
641
- type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
638
+ type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]>; }> : {
642
639
  [option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
643
640
  };
644
641
  /**
@@ -670,7 +667,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
670
667
  *
671
668
  * @internal
672
669
  */
673
- type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg] } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg] } extends (infer P) ? { [K in keyof P]: P[K] } : never;
670
+ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg]; } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg]; } extends (infer P) ? { [K in keyof P]: P[K]; } : never;
674
671
  /**
675
672
  * Whether an argument with the schema `S` has a value: with a default, with `required: true` or as
676
673
  * a required positional argument. For a union of schemas, only when each schema of the union has
@@ -678,16 +675,6 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
678
675
  * value, as {@link FilterArgs} does.
679
676
  */
680
677
  type IsPresentArg<S extends ArgSchema> = S extends ArgSchema ? true extends (S['default'] extends {} ? true : S['required'] extends true ? true : false) ? true : IsRequiredPositionalArg<S> : never;
681
- /**
682
- * Filters the arguments based on their default values.
683
- *
684
- * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
685
- * @typeParam V - Resolvable argument values.
686
- * @typeParam K - Key of the {@link ArgSchema | argument schema} to filter by.
687
- *
688
- * @internal
689
- */
690
-
691
678
  type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : MayBeUnrequired<A> extends true ? A['default'] extends {} ? true : false : true : false;
692
679
  /**
693
680
  * Whether the `required` of `A` may be `false`. An optional `required` of type `boolean`, as in
@@ -698,10 +685,6 @@ type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positiona
698
685
  type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] extends [{
699
686
  required: unknown;
700
687
  }] ? true : boolean | undefined extends A['required'] ? false : true : false;
701
- /**
702
- * An arguments for {@link resolveArgs | resolve arguments}.
703
- */
704
-
705
688
  /**
706
689
  * Tracks which arguments were explicitly provided by the user.
707
690
  *
@@ -714,7 +697,7 @@ type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] ex
714
697
  *
715
698
  * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
716
699
  */
717
- type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
700
+ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean; };
718
701
  //#endregion
719
702
  //#region ../gunshi/src/types.d.ts
720
703
  /**
@@ -1366,23 +1349,24 @@ type CommonArgType = {
1366
1349
  declare const COMMON_ARGS: CommonArgType;
1367
1350
  declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES"];
1368
1351
  declare const ARG_ERROR_RESOURCE_KEYS: readonly ["err:arg:required-option", "err:arg:required-positional", "err:arg:invalid-type", "err:arg:invalid-choice", "err:arg:custom-parse", "err:arg:unknown-option", "err:arg:unexpected-value", "err:arg:missing-value", "err:arg:conflict", "err:arg:invalid-default"];
1352
+ declare const ARG_ERROR_HINT_RESOURCE_KEYS: readonly ["err:arg:missing-value:hint"];
1369
1353
  declare const COMMAND_ERROR_RESOURCE_KEYS: readonly ["err:cmd:not-found", "err:cmd:ambiguous", "err:cmd:inconsistent-options", "err:cmd:lazy-schema-mismatch"];
1370
1354
  declare const SUGGESTION_ERROR_RESOURCE_KEYS: readonly ["err:suggestion:did-you-mean"];
1371
1355
  //#endregion
1372
1356
  //#region src/types.d.ts
1373
- type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
1357
+ type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; };
1374
1358
  /**
1375
- * Make all properties in T deeply writeable (not readonly)
1359
+ * Make all properties in T deeply writable (not readonly)
1376
1360
  */
1377
- type DeepWriteable<T> = T extends ((...args: any) => any) ? T : T extends readonly (infer U)[] ? DeepWriteable<U>[] : T extends object ? { -readonly [P in keyof T]: DeepWriteable<T[P]> } : T;
1361
+ type DeepWriteable<T> = T extends ((...args: any) => any) ? T : T extends readonly (infer U)[] ? DeepWriteable<U>[] : T extends object ? { -readonly [P in keyof T]: DeepWriteable<T[P]>; } : T;
1378
1362
  /**
1379
1363
  * Remove index signature from object or record type.
1380
1364
  */
1381
- type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
1365
+ type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K]; }>;
1382
1366
  /**
1383
1367
  * Resolve a key on {@link Args}.
1384
1368
  */
1385
- type KeyOfArgs<A extends Args> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A];
1369
+ type KeyOfArgs<A extends Args> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never; }[keyof A];
1386
1370
  /**
1387
1371
  * Generate a namespaced key.
1388
1372
  */
@@ -1399,6 +1383,10 @@ type CommandBuiltinResourceKeys = (typeof COMMAND_BUILTIN_RESOURCE_KEYS)[number]
1399
1383
  * Args validation error resource keys.
1400
1384
  */
1401
1385
  type ArgErrorResourceKeys = (typeof ARG_ERROR_RESOURCE_KEYS)[number];
1386
+ /**
1387
+ * Resource keys of the hints that follow an args validation error.
1388
+ */
1389
+ type ArgErrorHintResourceKeys = (typeof ARG_ERROR_HINT_RESOURCE_KEYS)[number];
1402
1390
  /**
1403
1391
  * Command validation error resource keys.
1404
1392
  */
@@ -1410,7 +1398,7 @@ type SuggestionErrorResourceKeys = (typeof SUGGESTION_ERROR_RESOURCE_KEYS)[numbe
1410
1398
  /**
1411
1399
  * Error resource keys.
1412
1400
  */
1413
- type ErrorResourceKeys = ArgErrorResourceKeys | CommandErrorResourceKeys | SuggestionErrorResourceKeys;
1401
+ type ErrorResourceKeys = ArgErrorResourceKeys | ArgErrorHintResourceKeys | CommandErrorResourceKeys | SuggestionErrorResourceKeys;
1414
1402
  /**
1415
1403
  * Built-in resource keys.
1416
1404
  */
@@ -1433,21 +1421,17 @@ type CommandArgKeys<A extends Args, C = {}, K extends string = GenerateNamespace
1433
1421
  /**
1434
1422
  * Resolve translation keys for command context.
1435
1423
  */
1436
- type ResolveTranslationKeys<A extends Args, C = {},
1437
- // for CommandContext
1438
- E extends Record<string, string> = {},
1439
- // for extended resources
1440
- R extends string = keyof RemovedIndex<E>, T extends string = (C extends {
1424
+ type ResolveTranslationKeys<A extends Args, C = {} // for CommandContext
1425
+ , E extends Record<string, string> = {} // for extended resources
1426
+ , R extends string = keyof RemovedIndex<E>, T extends string = C extends {
1441
1427
  name: infer N;
1442
- } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A, C>> = ErrorResourceKeys | CommandBuiltinKeys | O | T;
1428
+ } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys, O = CommandArgKeys<A, C>> = ErrorResourceKeys | CommandBuiltinKeys | O | T;
1443
1429
  /**
1444
1430
  * Translation function interface
1445
1431
  */
1446
- interface Translation<A extends Args, C = {},
1447
- // for CommandContext
1448
- E extends Record<string, string> = {},
1449
- // for extended resources
1450
- K = ResolveTranslationKeys<A, C, E>> {
1432
+ interface Translation<A extends Args, C = {} // for CommandContext
1433
+ , E extends Record<string, string> = {} // for extended resources
1434
+ , K = ResolveTranslationKeys<A, C, E>> {
1451
1435
  (key: K, values?: Record<string, unknown>): string;
1452
1436
  }
1453
1437
  //#endregion
@@ -1459,9 +1443,8 @@ K = ResolveTranslationKeys<A, C, E>> {
1459
1443
  * @typeParam C - Additional context type for command localization.
1460
1444
  * @typeParam E - Extended resource keys type.
1461
1445
  */
1462
- interface Localization<A extends Args, C = {},
1463
- // for CommandContext
1464
- E extends Record<string, string> = {}> {
1446
+ interface Localization<A extends Args, C = {} // for CommandContext
1447
+ , E extends Record<string, string> = {}> {
1465
1448
  <K = ResolveTranslationKeys<A, C, E>>(key: K, values?: Record<string, unknown>): Promise<string>;
1466
1449
  }
1467
1450
  /**
@@ -1478,11 +1461,9 @@ E extends Record<string, string> = {}> {
1478
1461
  * @param translate - Translation function
1479
1462
  * @returns Localizable function
1480
1463
  */
1481
- declare function localizable<A extends Args, C = {},
1482
- // for CommandContext
1483
- E extends Record<string, string> = {},
1484
- // for extended resources
1485
- K = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translate?: Translation<A, C, E, K>): Localization<A, C, E>;
1464
+ declare function localizable<A extends Args, C = {} // for CommandContext
1465
+ , E extends Record<string, string> = {} // for extended resources
1466
+ , K = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translate?: Translation<A, C, E, K>): Localization<A, C, E>;
1486
1467
  /**
1487
1468
  * Format a resource message by replacing placeholder values.
1488
1469
  *
@@ -1492,7 +1473,7 @@ K = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translat
1492
1473
  */
1493
1474
  declare function formatResource(resource: string | undefined, values?: Record<string, unknown>): string | undefined;
1494
1475
  //#endregion
1495
- //#region ../resources/locales/en-US.d.ts
1476
+ //#region ../resources/locales/en-US.json.d.ts
1496
1477
  declare const _exports: {
1497
1478
  COMMAND: string;
1498
1479
  COMMANDS: string;
@@ -1515,6 +1496,7 @@ declare const _exports: {
1515
1496
  "err:arg:unknown-option": string;
1516
1497
  "err:arg:unexpected-value": string;
1517
1498
  "err:arg:missing-value": string;
1499
+ "err:arg:missing-value:hint": string;
1518
1500
  "err:arg:conflict": string;
1519
1501
  "err:arg:invalid-default": string;
1520
1502
  "err:cmd:not-found": string;
@@ -1560,7 +1542,7 @@ declare function resolveArgKey<A extends Args = DefaultGunshiParams['args'], K e
1560
1542
  * @param name - The command name.
1561
1543
  * @returns Prefixed non-built-in key.
1562
1544
  */
1563
- declare function resolveKey<T extends Record<string, string> = {}, K extends string = (keyof T extends string ? keyof T : string)>(key: K, name?: string): string;
1545
+ declare function resolveKey<T extends Record<string, string> = {}, K extends string = keyof T extends string ? keyof T : string>(key: K, name?: string): string;
1564
1546
  /**
1565
1547
  * Resolve command examples.
1566
1548
  *
@@ -1610,11 +1592,4 @@ declare function resolveDisplayName(name: string, schema: ArgSchema, toKebab?: b
1610
1592
  */
1611
1593
  declare function resolveOptionNames(args: Args, toKebab?: boolean): Set<string>;
1612
1594
  //#endregion
1613
- //#region src/index.d.ts
1614
- /**
1615
- * @author kazuya kawaguchi (a.k.a. kazupon)
1616
- * @license MIT
1617
- */
1618
-
1619
- //#endregion
1620
- export { ARG_ERROR_RESOURCE_KEYS, ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, ArgErrorResourceKeys, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, BuiltinResource, BuiltinResourceKeys, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_ERROR_RESOURCE_KEYS, COMMON_ARGS, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandErrorResourceKeys, DeepWriteable, _exports as DefaultResource, ERROR_PREFIX, ERROR_PREFIX_AND_KEY_SEPARATOR, ErrorResourceKeys, GenerateNamespacedKey, KeyOfArgs, Localization, PLUGIN_PREFIX, RemovedIndex, ResolveTranslationKeys, SUGGESTION_ERROR_RESOURCE_KEYS, SuggestionErrorResourceKeys, Translation, create, deepFreeze, formatResource, getCommandSubCommands, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveCommandArgs, resolveDisplayName, resolveExamples, resolveKey, resolveLazyCommand, resolveOptionNames };
1595
+ export { ARG_ERROR_HINT_RESOURCE_KEYS, ARG_ERROR_RESOURCE_KEYS, ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, type ArgErrorHintResourceKeys, type ArgErrorResourceKeys, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, type BuiltinResource, type BuiltinResourceKeys, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_ERROR_RESOURCE_KEYS, COMMON_ARGS, type CommandArgKeys, type CommandBuiltinArgsKeys, type CommandBuiltinKeys, type CommandBuiltinResourceKeys, type CommandErrorResourceKeys, type DeepWriteable, _exports as DefaultResource, ERROR_PREFIX, ERROR_PREFIX_AND_KEY_SEPARATOR, type ErrorResourceKeys, type GenerateNamespacedKey, type KeyOfArgs, Localization, PLUGIN_PREFIX, type RemovedIndex, type ResolveTranslationKeys, SUGGESTION_ERROR_RESOURCE_KEYS, type SuggestionErrorResourceKeys, type Translation, create, deepFreeze, formatResource, getCommandSubCommands, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveCommandArgs, resolveDisplayName, resolveExamples, resolveKey, resolveLazyCommand, resolveOptionNames };
package/lib/index.js CHANGED
@@ -225,6 +225,7 @@ const ARG_ERROR_RESOURCE_KEYS = [
225
225
  "err:arg:conflict",
226
226
  "err:arg:invalid-default"
227
227
  ];
228
+ const ARG_ERROR_HINT_RESOURCE_KEYS = ["err:arg:missing-value:hint"];
228
229
  const COMMAND_ERROR_RESOURCE_KEYS = [
229
230
  "err:cmd:not-found",
230
231
  "err:cmd:ambiguous",
@@ -249,13 +250,14 @@ var en_US_default = {
249
250
  help: "Display this help message",
250
251
  version: "Display this version",
251
252
  "err:arg:required-option": "Optional argument {$displayName} is required",
252
- "err:arg:required-positional": "Positional argument {$name} is required",
253
+ "err:arg:required-positional": "Positional argument {$displayName} is required",
253
254
  "err:arg:invalid-type": "Invalid value for {$displayName}: expected {$expected}",
254
255
  "err:arg:invalid-choice": "Invalid value for {$displayName}: expected one of {$choices}",
255
256
  "err:arg:custom-parse": "Invalid value for {$displayName}: {$reason}",
256
257
  "err:arg:unknown-option": "Unknown option: {$rawName}",
257
258
  "err:arg:unexpected-value": "Optional argument {$displayName} does not take a value",
258
259
  "err:arg:missing-value": "Optional argument {$displayName} requires a value",
260
+ "err:arg:missing-value:hint": "(to pass '{$next}' as its value, write '{$suggestion}')",
259
261
  "err:arg:conflict": "{$displayName} conflicts with {$conflictDisplayName}",
260
262
  "err:arg:invalid-default": "Invalid default for {$displayName}: {$actual} is not one of {$choices}",
261
263
  "err:cmd:not-found": "Command not found: {$commandName}",
@@ -445,4 +447,4 @@ function formatResource(resource, values = Object.create(null)) {
445
447
  * @license MIT
446
448
  */
447
449
  //#endregion
448
- export { ARG_ERROR_RESOURCE_KEYS, ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_ERROR_RESOURCE_KEYS, COMMON_ARGS, en_US_default as DefaultResource, ERROR_PREFIX, ERROR_PREFIX_AND_KEY_SEPARATOR, PLUGIN_PREFIX, SUGGESTION_ERROR_RESOURCE_KEYS, create, deepFreeze, formatResource, getCommandSubCommands, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveCommandArgs, resolveDisplayName, resolveExamples, resolveKey, resolveLazyCommand, resolveOptionNames };
450
+ export { ARG_ERROR_HINT_RESOURCE_KEYS, ARG_ERROR_RESOURCE_KEYS, ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_ERROR_RESOURCE_KEYS, COMMON_ARGS, en_US_default as DefaultResource, ERROR_PREFIX, ERROR_PREFIX_AND_KEY_SEPARATOR, PLUGIN_PREFIX, SUGGESTION_ERROR_RESOURCE_KEYS, create, deepFreeze, formatResource, getCommandSubCommands, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveCommandArgs, resolveDisplayName, resolveExamples, resolveKey, resolveLazyCommand, resolveOptionNames };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/shared",
3
3
  "description": "shared utils for gunshi",
4
- "version": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -50,13 +50,13 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
+ "@gunshi/resources": "1.0.0-beta.1",
53
54
  "deno": "^2.7.14",
55
+ "gunshi": "1.0.0-beta.1",
54
56
  "jsr": "^0.14.3",
55
57
  "jsr-exports-lint": "^0.4.2",
56
58
  "publint": "^0.3.20",
57
- "tsdown": "0.21.0",
58
- "@gunshi/resources": "1.0.0-beta.0",
59
- "gunshi": "1.0.0-beta.0"
59
+ "tsdown": "0.22.14"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsdown",