@gunshi/shared 1.0.0-beta.1 → 1.0.0-beta.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/index.d.ts CHANGED
@@ -1285,19 +1285,6 @@ declare function resolveLazyCommand<G extends GunshiParamsConstraint = DefaultGu
1285
1285
  * @returns A new object with the specified prototype
1286
1286
  */
1287
1287
  declare function create<T>(obj?: object | null): T;
1288
- /**
1289
- * Resolve the arguments of a command, the way gunshi parses and renders them.
1290
- *
1291
- * The global options belong to no command definition, so they are merged into the arguments of the
1292
- * command that runs. An argument of the command shadows the global option of the same name, and it
1293
- * shadows the same way by short name: a global option gives up its short name to an argument of the
1294
- * command that claims the same letter, and keeps its long name.
1295
- *
1296
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
1297
- * @param args - The arguments that the command declares
1298
- * @returns The merged arguments
1299
- */
1300
- declare function resolveCommandArgs<A extends Args = Args>(globalOptions?: ReadonlyMap<string, ArgSchema>, args?: A): A;
1301
1288
  /**
1302
1289
  * Log a message to the console.
1303
1290
  *
@@ -1591,5 +1578,22 @@ declare function resolveDisplayName(name: string, schema: ArgSchema, toKebab?: b
1591
1578
  * @returns The set of names.
1592
1579
  */
1593
1580
  declare function resolveOptionNames(args: Args, toKebab?: boolean): Set<string>;
1581
+ /**
1582
+ * Resolve the arguments of a command, the way gunshi parses and renders them.
1583
+ *
1584
+ * The global options belong to no command definition, so they are merged into the arguments of the
1585
+ * command. An argument of the command shadows the global option of the same name, and it shadows the
1586
+ * same way by short name: a global option gives up its short name to an argument of the command that
1587
+ * claims the same letter, and keeps its long name.
1588
+ *
1589
+ * NOTE(kazupon): a copy of the function that the core of gunshi resolves the arguments with. The
1590
+ * core does not export its own, to keep it out of the public API. `@gunshi/plugin-completion`
1591
+ * completes the arguments with this copy, and the tests pin it to the results of the core.
1592
+ *
1593
+ * @param globalOptions - The global options that plugins registered with `addGlobalOption`.
1594
+ * @param args - The {@linkcode Args | arguments} that the command declares.
1595
+ * @returns The merged arguments.
1596
+ */
1597
+ declare function resolveCommandArgs<A extends Args = Args>(globalOptions?: ReadonlyMap<string, ArgSchema>, args?: A): A;
1594
1598
  //#endregion
1595
1599
  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
@@ -101,37 +101,6 @@ function create(obj = null) {
101
101
  return Object.create(obj);
102
102
  }
103
103
  /**
104
- * Resolve the arguments of a command, the way gunshi parses and renders them.
105
- *
106
- * The global options belong to no command definition, so they are merged into the arguments of the
107
- * command that runs. An argument of the command shadows the global option of the same name, and it
108
- * shadows the same way by short name: a global option gives up its short name to an argument of the
109
- * command that claims the same letter, and keeps its long name.
110
- *
111
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
112
- * @param args - The arguments that the command declares
113
- * @returns The merged arguments
114
- */
115
- function resolveCommandArgs(globalOptions, args) {
116
- return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
117
- }
118
- function resolveGlobalOptions(globalOptions, args) {
119
- if (!globalOptions) return;
120
- const shortNames = /* @__PURE__ */ new Set();
121
- for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
122
- const resolved = create();
123
- for (const [name, schema] of globalOptions)
124
- /**
125
- * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
126
- * command of the CLI shares. Only this command gives up the short name.
127
- */
128
- resolved[name] = schema.short && shortNames.has(schema.short) ? {
129
- ...schema,
130
- short: void 0
131
- } : schema;
132
- return resolved;
133
- }
134
- /**
135
104
  * Log a message to the console.
136
105
  *
137
106
  * @param args - Arguments to log
@@ -376,6 +345,41 @@ function resolveOptionNames(args, toKebab) {
376
345
  for (const [name, schema] of Object.entries(args)) if (schema.type !== "positional") names.add(resolveDisplayName(name, schema, toKebab));
377
346
  return names;
378
347
  }
348
+ /**
349
+ * Resolve the arguments of a command, the way gunshi parses and renders them.
350
+ *
351
+ * The global options belong to no command definition, so they are merged into the arguments of the
352
+ * command. An argument of the command shadows the global option of the same name, and it shadows the
353
+ * same way by short name: a global option gives up its short name to an argument of the command that
354
+ * claims the same letter, and keeps its long name.
355
+ *
356
+ * NOTE(kazupon): a copy of the function that the core of gunshi resolves the arguments with. The
357
+ * core does not export its own, to keep it out of the public API. `@gunshi/plugin-completion`
358
+ * completes the arguments with this copy, and the tests pin it to the results of the core.
359
+ *
360
+ * @param globalOptions - The global options that plugins registered with `addGlobalOption`.
361
+ * @param args - The {@linkcode Args | arguments} that the command declares.
362
+ * @returns The merged arguments.
363
+ */
364
+ function resolveCommandArgs(globalOptions, args) {
365
+ return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
366
+ }
367
+ function resolveGlobalOptions(globalOptions, args) {
368
+ if (!globalOptions) return;
369
+ const shortNames = /* @__PURE__ */ new Set();
370
+ for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
371
+ const resolved = create();
372
+ for (const [name, schema] of globalOptions)
373
+ /**
374
+ * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
375
+ * command of the CLI shares. Only this command gives up the short name.
376
+ */
377
+ resolved[name] = schema.short && shortNames.has(schema.short) ? {
378
+ ...schema,
379
+ short: void 0
380
+ } : schema;
381
+ return resolved;
382
+ }
379
383
  //#endregion
380
384
  //#region src/localization.ts
381
385
  /**
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.1",
4
+ "version": "1.0.0-beta.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -50,9 +50,9 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
- "@gunshi/resources": "1.0.0-beta.1",
53
+ "@gunshi/resources": "1.0.0-beta.2",
54
54
  "deno": "^2.7.14",
55
- "gunshi": "1.0.0-beta.1",
55
+ "gunshi": "1.0.0-beta.2",
56
56
  "jsr": "^0.14.3",
57
57
  "jsr-exports-lint": "^0.4.2",
58
58
  "publint": "^0.3.20",