@kaynooo/cli-code 0.5.0 → 0.6.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/dist/todo-scan.js CHANGED
@@ -2,12 +2,11 @@
2
2
  // @bun
3
3
 
4
4
  // src/todo-scan.ts
5
- import { join as join2 } from "path";
6
- import process7 from "process";
5
+ import { join as join3 } from "path";
6
+ import process9 from "process";
7
7
 
8
8
  // ../kit/src/args.ts
9
- import { fstatSync } from "fs";
10
- import process3 from "process";
9
+ import process4 from "process";
11
10
  import { parseArgs } from "util";
12
11
 
13
12
  // ../kit/src/format.ts
@@ -16,7 +15,7 @@ import process2 from "process";
16
15
  // ../kit/src/style.ts
17
16
  import process from "process";
18
17
 
19
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
20
19
  function x(s) {
21
20
  let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
22
21
  if (!/^[a-f0-9]+$/.test(r))
@@ -236,7 +235,7 @@ class e {
236
235
  }
237
236
  }
238
237
 
239
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
240
239
  var r = 39;
241
240
  var o = 49;
242
241
  var f2 = "\x1B[";
@@ -360,6 +359,55 @@ function printJson(value) {
360
359
  console.log(JSON.stringify(value, undefined, 2));
361
360
  }
362
361
 
362
+ // ../kit/src/help.ts
363
+ import process3 from "process";
364
+ var OPTIONAL = /\[[^\]]+\]/g;
365
+ var USAGE_PREFIX = /^usage:\s*/i;
366
+ var FULL_STOP = /\.$/;
367
+ function usageLine(usage, colors = paint(process3.stdout)) {
368
+ return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
369
+ }
370
+ function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
371
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
372
+ `);
373
+ }
374
+ function replacesRows(replaces, colors = paint(process3.stdout)) {
375
+ return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
376
+ }
377
+ function wantsHelpJson(env = process3.env) {
378
+ return env.KIT_HELP === "json";
379
+ }
380
+ function description(usage, { examples = [], replaces } = {}) {
381
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
382
+ `);
383
+ const first = lines[0];
384
+ const colon = first.indexOf(": ");
385
+ const prose = lines[lines.indexOf("") + 1] ?? "";
386
+ const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
387
+ return {
388
+ synopsis: colon === -1 ? first : first.slice(0, colon),
389
+ summary: colon === -1 ? fallback : first.slice(colon + 2),
390
+ ...replaces === undefined ? {} : { replaces },
391
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
392
+ };
393
+ }
394
+ function exampleRows(examples, colors = paint(process3.stdout)) {
395
+ if (examples.length === 0)
396
+ return [];
397
+ return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
398
+ }
399
+ function optionRows(options, colors = paint(process3.stdout)) {
400
+ const rows = Object.entries(options).map(([name, option]) => {
401
+ const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
402
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
403
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
404
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
405
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
406
+ });
407
+ const width = Math.max(0, ...rows.map((row) => row.width));
408
+ return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
409
+ }
410
+
363
411
  // ../kit/src/text.ts
364
412
  var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
365
413
  function distance(a, b) {
@@ -379,8 +427,24 @@ function closest(name, names) {
379
427
  const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
380
428
  return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
381
429
  }
430
+ // ../kit/src/input.ts
431
+ import { fstatSync } from "fs";
432
+ var WHOLE = /^\d+$/;
433
+ function wholeNumber(value, name, fallback, min = 1) {
434
+ if (value === undefined)
435
+ return fallback;
436
+ const number = Number(value);
437
+ if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
438
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
439
+ return number;
440
+ }
441
+ function isStdinPiped() {
442
+ const stat = fstatSync(0);
443
+ return stat.isFIFO() || stat.isFile();
444
+ }
382
445
 
383
446
  // ../kit/src/args.ts
447
+ var DASHES = /^-+/;
384
448
  function jsonOption(holds) {
385
449
  return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
386
450
  }
@@ -415,61 +479,20 @@ class HelpShown extends Exit {
415
479
 
416
480
  class Completing {
417
481
  options;
418
- constructor(options) {
482
+ positionals;
483
+ candidates;
484
+ constructor(options, positionals = [], candidates = {}) {
419
485
  this.options = options;
486
+ this.positionals = positionals;
487
+ this.candidates = candidates;
420
488
  }
421
489
  }
422
490
  var completion = { active: false };
423
- var OPTIONAL = /\[[^\]]+\]/g;
424
- var USAGE_PREFIX = /^usage:\s*/i;
425
- var FULL_STOP = /\.$/;
426
- var DASHES = /^-+/;
427
- function usageLine(usage, colors = paint(process3.stdout)) {
428
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
429
- }
430
- function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
431
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
432
- `);
433
- }
434
- function replacesRows(replaces, colors = paint(process3.stdout)) {
435
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
436
- }
437
- function wantsHelpJson(env = process3.env) {
438
- return env.KIT_HELP === "json";
439
- }
440
- function description(usage, { examples = [], replaces } = {}) {
441
- const lines = usage.replace(USAGE_PREFIX, "").split(`
442
- `);
443
- const first = lines[0];
444
- const colon = first.indexOf(": ");
445
- const prose = lines[lines.indexOf("") + 1] ?? "";
446
- const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
447
- return {
448
- synopsis: colon === -1 ? first : first.slice(0, colon),
449
- summary: colon === -1 ? fallback : first.slice(colon + 2),
450
- ...replaces === undefined ? {} : { replaces },
451
- examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
452
- };
453
- }
454
- function exampleRows(examples, colors = paint(process3.stdout)) {
455
- if (examples.length === 0)
456
- return [];
457
- return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
458
- }
459
- function optionRows(options, colors = paint(process3.stdout)) {
460
- const rows = Object.entries(options).map(([name, option]) => {
461
- const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
462
- const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
463
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
464
- });
465
- const width = Math.max(0, ...rows.map((row) => row.width));
466
- return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
467
- }
468
491
  var OUTPUT_OPTIONS = {
469
492
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
470
493
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
471
494
  };
472
- function applyOutput(color, plain, env = process3.env) {
495
+ function applyOutput(color, plain, env = process4.env) {
473
496
  const when = plain === true ? "never" : color ?? "auto";
474
497
  if (when === "auto")
475
498
  return;
@@ -486,14 +509,13 @@ function applyOutput(color, plain, env = process3.env) {
486
509
  function parse(args, usage, options, settings = {}) {
487
510
  const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
488
511
  const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
512
+ const listing = listed(all, settings.allowNegative === true);
489
513
  if (completion.active)
490
- throw new Completing(all);
491
- const separator = settings.rest === true ? args.indexOf("--") : -1;
492
- const own = separator === -1 ? args : args.slice(0, separator);
493
- const rest = separator === -1 ? undefined : args.slice(separator + 1);
514
+ throw new Completing(listing, settings.positionals, settings.candidates);
515
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
494
516
  let parsed;
495
517
  try {
496
- parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
518
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
497
519
  } catch (error) {
498
520
  const message = parseError(error);
499
521
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -501,12 +523,84 @@ function parse(args, usage, options, settings = {}) {
501
523
  const values = parsed.values;
502
524
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
503
525
  if (values.help === true) {
504
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
526
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
505
527
  throw new HelpShown;
506
528
  }
529
+ checkChoices(parsed.values, all);
530
+ checkConflicts(parsed.values, all);
507
531
  if (settings.positionals !== undefined)
508
532
  checkPositionals(parsed.positionals, settings.positionals);
509
- return { ...parsed, positionals: parsed.positionals, rest };
533
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
534
+ }
535
+ function splitRest(args, passes) {
536
+ const separator = passes ? args.indexOf("--") : -1;
537
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
538
+ }
539
+ function splitTrailing(args, options, count) {
540
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
541
+ let seen = 0;
542
+ if (count === 0)
543
+ return { own: args, rest: undefined };
544
+ for (let at = 0;at < args.length; at++) {
545
+ const word = args[at];
546
+ if (word === "--")
547
+ break;
548
+ if (word.startsWith("-")) {
549
+ if (takesValue(word))
550
+ at++;
551
+ continue;
552
+ }
553
+ seen++;
554
+ if (seen === count)
555
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
556
+ }
557
+ return { own: args, rest: undefined };
558
+ }
559
+ function listed(options, allowNegative) {
560
+ if (!allowNegative)
561
+ return options;
562
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
563
+ if (option.type !== "boolean" || option.negative === undefined)
564
+ return [[name, option]];
565
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
566
+ }));
567
+ }
568
+ function withBare(args, options) {
569
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
570
+ if (bare.size === 0)
571
+ return args;
572
+ const separator = args.indexOf("--");
573
+ const own = separator === -1 ? args : args.slice(0, separator);
574
+ return [...own.flatMap((arg, index) => {
575
+ const optional = bare.get(arg);
576
+ const next = own[index + 1];
577
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
578
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
579
+ }), ...separator === -1 ? [] : args.slice(separator)];
580
+ }
581
+ function checkConflicts(values, options) {
582
+ const given = (name) => values[name] !== undefined && values[name] !== false;
583
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
584
+ const other = given(name) ? conflicts.find(given) : undefined;
585
+ if (other !== undefined)
586
+ badUsage(`--${name} cannot be used with --${other}`);
587
+ }
588
+ }
589
+ function checkChoices(values, options) {
590
+ for (const [name, option] of Object.entries(options)) {
591
+ if (option.choices === undefined)
592
+ continue;
593
+ const given = values[name];
594
+ for (const value of Array.isArray(given) ? given : [given]) {
595
+ if (typeof value === "string")
596
+ oneOf(value, name, option.choices);
597
+ }
598
+ }
599
+ }
600
+ function oneOf(value, name, choices) {
601
+ if (!choices.includes(value))
602
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
603
+ return value;
510
604
  }
511
605
  function checkPositionals(given, names) {
512
606
  const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
@@ -555,22 +649,9 @@ function nearestOption(message, options, allowNegative) {
555
649
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
556
650
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
557
651
  }
558
- var WHOLE = /^\d+$/;
559
- function wholeNumber(value, name, fallback, min = 1) {
560
- if (value === undefined)
561
- return fallback;
562
- const number = Number(value);
563
- if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
564
- badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
565
- return number;
566
- }
567
- function isStdinPiped() {
568
- const stat = fstatSync(0);
569
- return stat.isFIFO() || stat.isFile();
570
- }
571
652
  // ../kit/src/process.ts
572
653
  import { constants } from "os";
573
- import process4 from "process";
654
+ import process5 from "process";
574
655
  var KILL_GRACE_MS = 2000;
575
656
  function exitCodeOf(code, signal) {
576
657
  if (code !== null)
@@ -590,7 +671,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
590
671
  return;
591
672
  try {
592
673
  if (grouped)
593
- process4.kill(-proc.pid, killing);
674
+ process5.kill(-proc.pid, killing);
594
675
  else
595
676
  proc.kill(killing);
596
677
  } catch {}
@@ -664,15 +745,67 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
664
745
  var RESET_STYLE = `${ESC}[0m`;
665
746
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
666
747
  // ../kit/src/cli.ts
667
- import process5 from "process";
748
+ import process7 from "process";
749
+
750
+ // ../kit/src/usage.ts
751
+ import { appendFileSync, mkdirSync } from "fs";
752
+ import { homedir } from "os";
753
+ import { dirname, isAbsolute, join } from "path";
754
+ import process6 from "process";
755
+
756
+ // ../kit/src/logs.ts
757
+ var DAY_MS = 24 * 60 * 60 * 1000;
758
+ var CLI_FOLDER = "kaynooo-cli";
759
+
760
+ // ../kit/src/usage.ts
761
+ var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
762
+ var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
763
+ var LONGEST_NAME = 40;
764
+ var usageError;
765
+ function noteUsageError(message) {
766
+ usageError = message;
767
+ }
768
+ function stateHome(env = process6.env) {
769
+ const dir = env.XDG_STATE_HOME;
770
+ return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
771
+ }
772
+ function usagePath(env = process6.env) {
773
+ return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
774
+ }
775
+ function usageRecorded(env = process6.env) {
776
+ const off = env.KAYNOOO_CLI_NO_USAGE;
777
+ return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
778
+ }
779
+ function flagNames(argv) {
780
+ const end = argv.indexOf("--");
781
+ const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
782
+ return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
783
+ }
784
+ function usageEntry(bin, command, argv, code, now = new Date) {
785
+ const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
786
+ usageError = undefined;
787
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
788
+ }
789
+ function recordUsage(entry, env = process6.env) {
790
+ if (!usageRecorded(env))
791
+ return;
792
+ try {
793
+ const path = usagePath(env);
794
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
795
+ appendFileSync(path, `${JSON.stringify(entry)}
796
+ `, { mode: 384 });
797
+ } catch {}
798
+ }
799
+
800
+ // ../kit/src/cli.ts
668
801
  var LEVEL_OPTIONS = {
669
802
  ...OUTPUT_OPTIONS,
670
803
  help: { type: "boolean", short: "h", description: "show this help" }
671
804
  };
672
805
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
673
806
  function printError(prefix, message, hint, cause) {
674
- const colors = paint(process5.stderr);
675
- const styled = takesControlCodes(process5.stderr);
807
+ const colors = paint(process7.stderr);
808
+ const styled = takesControlCodes(process7.stderr);
676
809
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
677
810
  const under = (label, text, tint) => text === undefined ? "" : `
678
811
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -691,51 +824,90 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
691
824
  const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
692
825
  const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
693
826
  const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
827
+ if (error instanceof UsageError)
828
+ noteUsageError(error.message);
694
829
  const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
695
830
  report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
696
831
  return error instanceof Exit ? error.code : 1;
697
832
  }
698
833
  var COMPLETE = "__complete";
699
834
  var FILES = "__files__";
700
- async function optionsOf(run) {
835
+ async function completingOf(run) {
701
836
  completion.active = true;
702
837
  try {
703
838
  await run([]);
704
839
  } catch (error) {
705
840
  if (error instanceof Completing)
706
- return error.options;
841
+ return error;
707
842
  } finally {
708
843
  completion.active = false;
709
844
  }
710
- return {};
845
+ return new Completing({});
846
+ }
847
+ function candidateLine(candidate) {
848
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
849
+ }
850
+ function positionalBeingTyped(before, { options, positionals }) {
851
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
852
+ let index = 0;
853
+ let at = 0;
854
+ while (at < before.length) {
855
+ const word = before[at];
856
+ if (word === "--") {
857
+ index += before.length - at - 1;
858
+ break;
859
+ }
860
+ if (!word.startsWith("-"))
861
+ index++;
862
+ else if (takesValue(word))
863
+ at++;
864
+ at++;
865
+ }
866
+ const last = positionals.at(-1);
867
+ if (index < positionals.length)
868
+ return positionals[index];
869
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
711
870
  }
712
871
  async function leafCandidates(run, words) {
713
- if (!(words.at(-1) ?? "").startsWith("-"))
714
- return [FILES];
715
- return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
872
+ const completing = await completingOf(run);
873
+ if ((words.at(-1) ?? "").startsWith("-"))
874
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
875
+ const flag = words.at(-2);
876
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
877
+ if (option?.type === "string") {
878
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
879
+ return values === undefined ? [FILES] : values.map(candidateLine);
880
+ }
881
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
882
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
883
+ return values === undefined ? [FILES] : values.map(candidateLine);
716
884
  }
717
885
  async function printCandidates(found) {
718
886
  for (const line of await found)
719
887
  console.log(line);
720
888
  return 0;
721
889
  }
722
- async function runMain({ name, version, run, redact }, argv = process5.argv.slice(2)) {
890
+ async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
723
891
  if (argv[0] === COMPLETE)
724
892
  return printCandidates(leafCandidates(run, argv.slice(1)));
725
893
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
726
894
  console.log(version);
727
895
  return 0;
728
896
  }
897
+ let code;
729
898
  try {
730
- return await run(argv);
899
+ code = await run(argv);
731
900
  } catch (error) {
732
- return reportThrown(name, error, redact, wantsJson(argv));
901
+ code = reportThrown(name, error, redact, wantsJson(argv));
733
902
  }
903
+ if (usage !== false)
904
+ recordUsage(usageEntry(name, undefined, argv, code));
905
+ return code;
734
906
  }
735
907
  // ../kit/src/limit.ts
736
908
  function limitOptions(fallback) {
737
909
  return {
738
- limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
910
+ limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
739
911
  full: { type: "boolean", description: "show every row" }
740
912
  };
741
913
  }
@@ -753,8 +925,6 @@ function capped(rows, limit) {
753
925
  const more = rows.length - limit;
754
926
  return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
755
927
  }
756
- // ../kit/src/logs.ts
757
- var DAY_MS = 24 * 60 * 60 * 1000;
758
928
  // ../kit/src/secrets.ts
759
929
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
760
930
  // ../kit/src/sessions.ts
@@ -762,11 +932,11 @@ var {Glob } = globalThis.Bun;
762
932
  var SESSION_FILES = new Glob("*.json");
763
933
  var ACCOUNT_DIRS = new Glob("*/sessions");
764
934
  // package.json
765
- var version = "0.5.0";
935
+ var version = "0.6.1";
766
936
 
767
937
  // src/files.ts
768
938
  import { existsSync, readdirSync, statSync } from "fs";
769
- import { join, relative } from "path";
939
+ import { join as join2, relative } from "path";
770
940
  var MAX_BYTES = 2000000;
771
941
  var SNIFF_BYTES = 8000;
772
942
  var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
@@ -781,17 +951,17 @@ function walk(dir, found) {
781
951
  if (entry.name.startsWith(".") || SKIPPED.has(entry.name))
782
952
  continue;
783
953
  if (entry.isDirectory())
784
- walk(join(dir, entry.name), found);
954
+ walk(join2(dir, entry.name), found);
785
955
  else if (entry.isFile())
786
- found.push(join(dir, entry.name));
956
+ found.push(join2(dir, entry.name));
787
957
  }
788
958
  return found;
789
959
  }
790
960
  async function listFiles(paths, cwd) {
791
961
  const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
792
962
  if (listed.code === 0)
793
- return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join(cwd, path))).sort();
794
- const roots = paths.length === 0 ? [cwd] : paths.map((path) => join(cwd, path));
963
+ return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync(join2(cwd, path))).sort();
964
+ const roots = paths.length === 0 ? [cwd] : paths.map((path) => join2(cwd, path));
795
965
  return roots.flatMap((root) => statSync(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [])).map((path) => relative(cwd, path)).sort();
796
966
  }
797
967
  async function readText(path) {
@@ -895,11 +1065,11 @@ function printLines(lines, footer) {
895
1065
  }
896
1066
  async function main(args) {
897
1067
  const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
898
- const cwd = process7.cwd();
1068
+ const cwd = process9.cwd();
899
1069
  const limit = limitOf(values, LIST_LIMIT);
900
1070
  const marks = [];
901
1071
  for (const path of await listFiles(positionals, cwd)) {
902
- const text = await readText(join2(cwd, path));
1072
+ const text = await readText(join3(cwd, path));
903
1073
  if (text !== undefined)
904
1074
  marks.push(...marksIn(text, path));
905
1075
  }
@@ -924,4 +1094,4 @@ async function main(args) {
924
1094
  return 1;
925
1095
  return failed.size > 0 ? 2 : 0;
926
1096
  }
927
- process7.exitCode = await runMain({ name: "todo-scan", version, run: main });
1097
+ process9.exitCode = await runMain({ name: "todo-scan", version, run: main });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-code",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.1",
5
5
  "description": "peek, todo-scan and hotspots: source read by spans, symbols and outlines in one call, the TODO and issue-reference comments of a repository with stale ones flagged, and the files ranked by complexity times git churn.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -41,6 +41,6 @@
41
41
  "hotspots": "$npm_execpath src/hotspots.ts"
42
42
  },
43
43
  "devDependencies": {
44
- "@kaynooo/cli-kit": "0.15.0"
44
+ "@kaynooo/cli-kit": "0.20.0"
45
45
  }
46
46
  }