@optique/core 0.5.0 → 0.6.0-dev.102

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.
@@ -1,4 +1,5 @@
1
1
  import { Message } from "./message.cjs";
2
+ import { Suggestion } from "./parser.cjs";
2
3
 
3
4
  //#region src/valueparser.d.ts
4
5
 
@@ -35,6 +36,15 @@ interface ValueParser<T> {
35
36
  * @returns A string representation of the value.
36
37
  */
37
38
  format(value: T): string;
39
+ /**
40
+ * Provides completion suggestions for values of this type.
41
+ * This is optional and used for shell completion functionality.
42
+ *
43
+ * @param prefix The current input prefix to complete.
44
+ * @returns An iterable of suggestion objects.
45
+ * @since 0.6.0
46
+ */
47
+ suggest?(prefix: string): Iterable<Suggestion>;
38
48
  }
39
49
  /**
40
50
  * Result type returned by {@link ValueParser#parse}.
@@ -1,4 +1,5 @@
1
1
  import { Message } from "./message.js";
2
+ import { Suggestion } from "./parser.js";
2
3
 
3
4
  //#region src/valueparser.d.ts
4
5
 
@@ -35,6 +36,15 @@ interface ValueParser<T> {
35
36
  * @returns A string representation of the value.
36
37
  */
37
38
  format(value: T): string;
39
+ /**
40
+ * Provides completion suggestions for values of this type.
41
+ * This is optional and used for shell completion functionality.
42
+ *
43
+ * @param prefix The current input prefix to complete.
44
+ * @returns An iterable of suggestion objects.
45
+ * @since 0.6.0
46
+ */
47
+ suggest?(prefix: string): Iterable<Suggestion>;
38
48
  }
39
49
  /**
40
50
  * Result type returned by {@link ValueParser#parse}.
@@ -39,6 +39,16 @@ function choice(values, options = {}) {
39
39
  },
40
40
  format(value) {
41
41
  return value;
42
+ },
43
+ suggest(prefix) {
44
+ const normalizedPrefix = options.caseInsensitive ? prefix.toLowerCase() : prefix;
45
+ return values.filter((value) => {
46
+ const normalizedValue = options.caseInsensitive ? value.toLowerCase() : value;
47
+ return normalizedValue.startsWith(normalizedPrefix);
48
+ }).map((value) => ({
49
+ kind: "literal",
50
+ text: value
51
+ }));
42
52
  }
43
53
  };
44
54
  }
@@ -236,6 +246,15 @@ function url(options = {}) {
236
246
  },
237
247
  format(value) {
238
248
  return value.href;
249
+ },
250
+ *suggest(prefix) {
251
+ if (allowedProtocols && prefix.length > 0 && !prefix.includes("://")) for (const protocol of allowedProtocols) {
252
+ const cleanProtocol = protocol.replace(/:+$/, "");
253
+ if (cleanProtocol.startsWith(prefix.toLowerCase())) yield {
254
+ kind: "literal",
255
+ text: `${cleanProtocol}://`
256
+ };
257
+ }
239
258
  }
240
259
  };
241
260
  }
@@ -270,6 +289,236 @@ function locale(options = {}) {
270
289
  },
271
290
  format(value) {
272
291
  return value.baseName;
292
+ },
293
+ *suggest(prefix) {
294
+ const commonLocales = [
295
+ "en",
296
+ "en-US",
297
+ "en-GB",
298
+ "en-CA",
299
+ "en-AU",
300
+ "en-NZ",
301
+ "en-IE",
302
+ "en-ZA",
303
+ "en-IN",
304
+ "es",
305
+ "es-ES",
306
+ "es-MX",
307
+ "es-AR",
308
+ "es-CL",
309
+ "es-CO",
310
+ "es-PE",
311
+ "es-VE",
312
+ "es-EC",
313
+ "es-GT",
314
+ "es-CU",
315
+ "es-BO",
316
+ "es-DO",
317
+ "es-HN",
318
+ "es-PY",
319
+ "es-SV",
320
+ "es-NI",
321
+ "es-CR",
322
+ "es-PA",
323
+ "es-UY",
324
+ "es-PR",
325
+ "fr",
326
+ "fr-FR",
327
+ "fr-CA",
328
+ "fr-BE",
329
+ "fr-CH",
330
+ "fr-LU",
331
+ "fr-MC",
332
+ "de",
333
+ "de-DE",
334
+ "de-AT",
335
+ "de-CH",
336
+ "de-BE",
337
+ "de-LU",
338
+ "de-LI",
339
+ "it",
340
+ "it-IT",
341
+ "it-CH",
342
+ "it-SM",
343
+ "it-VA",
344
+ "pt",
345
+ "pt-BR",
346
+ "pt-PT",
347
+ "pt-AO",
348
+ "pt-MZ",
349
+ "pt-CV",
350
+ "pt-GW",
351
+ "pt-ST",
352
+ "pt-TL",
353
+ "ru",
354
+ "ru-RU",
355
+ "ru-BY",
356
+ "ru-KZ",
357
+ "ru-KG",
358
+ "ru-MD",
359
+ "uk",
360
+ "uk-UA",
361
+ "be",
362
+ "be-BY",
363
+ "bg",
364
+ "bg-BG",
365
+ "cs",
366
+ "cs-CZ",
367
+ "sk",
368
+ "sk-SK",
369
+ "sl",
370
+ "sl-SI",
371
+ "hr",
372
+ "hr-HR",
373
+ "sr",
374
+ "sr-RS",
375
+ "mk",
376
+ "mk-MK",
377
+ "ja",
378
+ "ja-JP",
379
+ "ko",
380
+ "ko-KR",
381
+ "zh",
382
+ "zh-CN",
383
+ "zh-TW",
384
+ "zh-HK",
385
+ "zh-SG",
386
+ "zh-MO",
387
+ "ar",
388
+ "ar-SA",
389
+ "ar-AE",
390
+ "ar-BH",
391
+ "ar-DZ",
392
+ "ar-EG",
393
+ "ar-IQ",
394
+ "ar-JO",
395
+ "ar-KW",
396
+ "ar-LB",
397
+ "ar-LY",
398
+ "ar-MA",
399
+ "ar-OM",
400
+ "ar-QA",
401
+ "ar-SY",
402
+ "ar-TN",
403
+ "ar-YE",
404
+ "hi",
405
+ "hi-IN",
406
+ "bn",
407
+ "bn-BD",
408
+ "bn-IN",
409
+ "ur",
410
+ "ur-PK",
411
+ "ta",
412
+ "ta-IN",
413
+ "te",
414
+ "te-IN",
415
+ "mr",
416
+ "mr-IN",
417
+ "gu",
418
+ "gu-IN",
419
+ "kn",
420
+ "kn-IN",
421
+ "ml",
422
+ "ml-IN",
423
+ "pa",
424
+ "pa-IN",
425
+ "tr",
426
+ "tr-TR",
427
+ "tr-CY",
428
+ "pl",
429
+ "pl-PL",
430
+ "nl",
431
+ "nl-NL",
432
+ "nl-BE",
433
+ "nl-SR",
434
+ "sv",
435
+ "sv-SE",
436
+ "sv-FI",
437
+ "da",
438
+ "da-DK",
439
+ "no",
440
+ "no-NO",
441
+ "nb",
442
+ "nb-NO",
443
+ "nn",
444
+ "nn-NO",
445
+ "fi",
446
+ "fi-FI",
447
+ "is",
448
+ "is-IS",
449
+ "el",
450
+ "el-GR",
451
+ "el-CY",
452
+ "hu",
453
+ "hu-HU",
454
+ "ro",
455
+ "ro-RO",
456
+ "et",
457
+ "et-EE",
458
+ "lv",
459
+ "lv-LV",
460
+ "lt",
461
+ "lt-LT",
462
+ "mt",
463
+ "mt-MT",
464
+ "ga",
465
+ "ga-IE",
466
+ "cy",
467
+ "cy-GB",
468
+ "eu",
469
+ "eu-ES",
470
+ "ca",
471
+ "ca-ES",
472
+ "ca-AD",
473
+ "th",
474
+ "th-TH",
475
+ "vi",
476
+ "vi-VN",
477
+ "id",
478
+ "id-ID",
479
+ "ms",
480
+ "ms-MY",
481
+ "ms-BN",
482
+ "ms-SG",
483
+ "tl",
484
+ "tl-PH",
485
+ "km",
486
+ "km-KH",
487
+ "my",
488
+ "my-MM",
489
+ "lo",
490
+ "lo-LA",
491
+ "si",
492
+ "si-LK",
493
+ "ne",
494
+ "ne-NP",
495
+ "sw",
496
+ "sw-TZ",
497
+ "sw-KE",
498
+ "am",
499
+ "am-ET",
500
+ "ha",
501
+ "ha-NG",
502
+ "yo",
503
+ "yo-NG",
504
+ "ig",
505
+ "ig-NG",
506
+ "zu",
507
+ "zu-ZA",
508
+ "xh",
509
+ "xh-ZA",
510
+ "af",
511
+ "af-ZA",
512
+ "he",
513
+ "he-IL",
514
+ "fa",
515
+ "fa-IR",
516
+ "fa-AF"
517
+ ];
518
+ for (const locale$1 of commonLocales) if (locale$1.toLowerCase().startsWith(prefix.toLowerCase())) yield {
519
+ kind: "literal",
520
+ text: locale$1
521
+ };
273
522
  }
274
523
  };
275
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-dev.102+50615c18",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -51,6 +51,14 @@
51
51
  "import": "./dist/index.js",
52
52
  "require": "./dist/index.cjs"
53
53
  },
54
+ "./completion": {
55
+ "types": {
56
+ "import": "./dist/completion.d.ts",
57
+ "require": "./dist/completion.cts"
58
+ },
59
+ "import": "./dist/completion.js",
60
+ "require": "./dist/completion.cjs"
61
+ },
54
62
  "./constructs": {
55
63
  "types": {
56
64
  "import": "./dist/constructs.d.ts",