@kaynooo/cli-code 0.5.0 → 0.6.0
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/README.md +1 -1
- package/dist/hotspots.js +130 -20
- package/dist/peek.js +130 -20
- package/dist/todo-scan.js +130 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,5 +38,5 @@ hotspots --since '3 months ago' --limit 10
|
|
|
38
38
|
|
|
39
39
|
- `hotspots [dir]` ranks the source files by complexity times churn, so the files both hard to read and often edited come first: rank, score, churn, complexity, lines, file. The files are the ones git keeps (`.gitignore` honoured).
|
|
40
40
|
- Churn is the commits touching the file since `--since` (any date git reads, `6 months ago` by default), counted from one `git log`. Complexity is the decision points of the file (`if`, loops, `case`, `catch`, `&&`, `||`, `??`, ternaries, `and`/`or`) plus one, counted with comments and strings blanked; it is computed in-house so the bin needs no dependency and reads any language the same way.
|
|
41
|
-
- `--limit <n>` sets how many files are listed (20, the count of the rest after them), `--full` lists all, `--json` is never cut unless `--limit` is given. `--all` keeps test files and generated files (`dist/`, `*.d.ts`, `*.min.js`, snapshots, files whose first lines say generated), `--json` prints `[{rank, path, score, churn, complexity, lines}]`.
|
|
41
|
+
- `--limit <n>` (`-n`) sets how many files are listed (20, the count of the rest after them), `--full` lists all, `--json` is never cut unless `--limit` is given. `--all` keeps test files and generated files (`dist/`, `*.d.ts`, `*.min.js`, snapshots, files whose first lines say generated), `--json` prints `[{rank, path, score, churn, complexity, lines}]`.
|
|
42
42
|
- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
|
package/dist/hotspots.js
CHANGED
|
@@ -16,7 +16,7 @@ import process2 from "process";
|
|
|
16
16
|
// ../kit/src/style.ts
|
|
17
17
|
import process from "process";
|
|
18
18
|
|
|
19
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
19
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
20
20
|
function x(s) {
|
|
21
21
|
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
22
22
|
if (!/^[a-f0-9]+$/.test(r))
|
|
@@ -236,7 +236,7 @@ class e {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
239
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
240
240
|
var r = 39;
|
|
241
241
|
var o = 49;
|
|
242
242
|
var f2 = "\x1B[";
|
|
@@ -415,8 +415,12 @@ class HelpShown extends Exit {
|
|
|
415
415
|
|
|
416
416
|
class Completing {
|
|
417
417
|
options;
|
|
418
|
-
|
|
418
|
+
positionals;
|
|
419
|
+
candidates;
|
|
420
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
419
421
|
this.options = options;
|
|
422
|
+
this.positionals = positionals;
|
|
423
|
+
this.candidates = candidates;
|
|
420
424
|
}
|
|
421
425
|
}
|
|
422
426
|
var completion = { active: false };
|
|
@@ -459,8 +463,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
|
459
463
|
function optionRows(options, colors = paint(process3.stdout)) {
|
|
460
464
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
461
465
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
462
|
-
const
|
|
463
|
-
|
|
466
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
467
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
468
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
469
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
464
470
|
});
|
|
465
471
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
466
472
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
@@ -486,14 +492,13 @@ function applyOutput(color, plain, env = process3.env) {
|
|
|
486
492
|
function parse(args, usage, options, settings = {}) {
|
|
487
493
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
488
494
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
495
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
489
496
|
if (completion.active)
|
|
490
|
-
throw new Completing(
|
|
491
|
-
const
|
|
492
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
493
|
-
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
497
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
498
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
494
499
|
let parsed;
|
|
495
500
|
try {
|
|
496
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
501
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
497
502
|
} catch (error) {
|
|
498
503
|
const message = parseError(error);
|
|
499
504
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -501,12 +506,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
501
506
|
const values = parsed.values;
|
|
502
507
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
503
508
|
if (values.help === true) {
|
|
504
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
509
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
505
510
|
throw new HelpShown;
|
|
506
511
|
}
|
|
512
|
+
checkChoices(parsed.values, all);
|
|
513
|
+
checkConflicts(parsed.values, all);
|
|
507
514
|
if (settings.positionals !== undefined)
|
|
508
515
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
509
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
516
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
517
|
+
}
|
|
518
|
+
function splitRest(args, passes) {
|
|
519
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
520
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
521
|
+
}
|
|
522
|
+
function splitTrailing(args, options, count) {
|
|
523
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
524
|
+
let seen = 0;
|
|
525
|
+
if (count === 0)
|
|
526
|
+
return { own: args, rest: undefined };
|
|
527
|
+
for (let at = 0;at < args.length; at++) {
|
|
528
|
+
const word = args[at];
|
|
529
|
+
if (word === "--")
|
|
530
|
+
break;
|
|
531
|
+
if (word.startsWith("-")) {
|
|
532
|
+
if (takesValue(word))
|
|
533
|
+
at++;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
seen++;
|
|
537
|
+
if (seen === count)
|
|
538
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
539
|
+
}
|
|
540
|
+
return { own: args, rest: undefined };
|
|
541
|
+
}
|
|
542
|
+
function listed(options, allowNegative) {
|
|
543
|
+
if (!allowNegative)
|
|
544
|
+
return options;
|
|
545
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
546
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
547
|
+
return [[name, option]];
|
|
548
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
function withBare(args, options) {
|
|
552
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
553
|
+
if (bare.size === 0)
|
|
554
|
+
return args;
|
|
555
|
+
const separator = args.indexOf("--");
|
|
556
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
557
|
+
return [...own.flatMap((arg, index) => {
|
|
558
|
+
const optional = bare.get(arg);
|
|
559
|
+
const next = own[index + 1];
|
|
560
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
561
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
562
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
563
|
+
}
|
|
564
|
+
function checkConflicts(values, options) {
|
|
565
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
566
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
567
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
568
|
+
if (other !== undefined)
|
|
569
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function checkChoices(values, options) {
|
|
573
|
+
for (const [name, option] of Object.entries(options)) {
|
|
574
|
+
if (option.choices === undefined)
|
|
575
|
+
continue;
|
|
576
|
+
const given = values[name];
|
|
577
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
578
|
+
if (typeof value === "string")
|
|
579
|
+
oneOf(value, name, option.choices);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function oneOf(value, name, choices) {
|
|
584
|
+
if (!choices.includes(value))
|
|
585
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
586
|
+
return value;
|
|
510
587
|
}
|
|
511
588
|
function checkPositionals(given, names) {
|
|
512
589
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -697,22 +774,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
697
774
|
}
|
|
698
775
|
var COMPLETE = "__complete";
|
|
699
776
|
var FILES = "__files__";
|
|
700
|
-
async function
|
|
777
|
+
async function completingOf(run) {
|
|
701
778
|
completion.active = true;
|
|
702
779
|
try {
|
|
703
780
|
await run([]);
|
|
704
781
|
} catch (error) {
|
|
705
782
|
if (error instanceof Completing)
|
|
706
|
-
return error
|
|
783
|
+
return error;
|
|
707
784
|
} finally {
|
|
708
785
|
completion.active = false;
|
|
709
786
|
}
|
|
710
|
-
return {};
|
|
787
|
+
return new Completing({});
|
|
788
|
+
}
|
|
789
|
+
function candidateLine(candidate) {
|
|
790
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
791
|
+
}
|
|
792
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
793
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
794
|
+
let index = 0;
|
|
795
|
+
let at = 0;
|
|
796
|
+
while (at < before.length) {
|
|
797
|
+
const word = before[at];
|
|
798
|
+
if (word === "--") {
|
|
799
|
+
index += before.length - at - 1;
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
if (!word.startsWith("-"))
|
|
803
|
+
index++;
|
|
804
|
+
else if (takesValue(word))
|
|
805
|
+
at++;
|
|
806
|
+
at++;
|
|
807
|
+
}
|
|
808
|
+
const last = positionals.at(-1);
|
|
809
|
+
if (index < positionals.length)
|
|
810
|
+
return positionals[index];
|
|
811
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
711
812
|
}
|
|
712
813
|
async function leafCandidates(run, words) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
814
|
+
const completing = await completingOf(run);
|
|
815
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
816
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
817
|
+
const flag = words.at(-2);
|
|
818
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
819
|
+
if (option?.type === "string") {
|
|
820
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
821
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
822
|
+
}
|
|
823
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
824
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
825
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
716
826
|
}
|
|
717
827
|
async function printCandidates(found) {
|
|
718
828
|
for (const line of await found)
|
|
@@ -735,7 +845,7 @@ async function runMain({ name, version, run, redact }, argv = process5.argv.slic
|
|
|
735
845
|
// ../kit/src/limit.ts
|
|
736
846
|
function limitOptions(fallback) {
|
|
737
847
|
return {
|
|
738
|
-
limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
848
|
+
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
739
849
|
full: { type: "boolean", description: "show every row" }
|
|
740
850
|
};
|
|
741
851
|
}
|
|
@@ -762,7 +872,7 @@ var {Glob } = globalThis.Bun;
|
|
|
762
872
|
var SESSION_FILES = new Glob("*.json");
|
|
763
873
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
764
874
|
// package.json
|
|
765
|
-
var version = "0.
|
|
875
|
+
var version = "0.6.0";
|
|
766
876
|
|
|
767
877
|
// src/churn.ts
|
|
768
878
|
var SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|py|go|rs|rb|php|java|kt|swift|cs|c|cc|cpp|h|hpp|scala|dart|lua|sh|zsh|fish)$/;
|
package/dist/peek.js
CHANGED
|
@@ -17,7 +17,7 @@ import process2 from "process";
|
|
|
17
17
|
// ../kit/src/style.ts
|
|
18
18
|
import process from "process";
|
|
19
19
|
|
|
20
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
20
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
21
21
|
function x(s) {
|
|
22
22
|
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
23
23
|
if (!/^[a-f0-9]+$/.test(r))
|
|
@@ -237,7 +237,7 @@ class e {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
240
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
241
241
|
var r = 39;
|
|
242
242
|
var o = 49;
|
|
243
243
|
var f2 = "\x1B[";
|
|
@@ -416,8 +416,12 @@ class HelpShown extends Exit {
|
|
|
416
416
|
|
|
417
417
|
class Completing {
|
|
418
418
|
options;
|
|
419
|
-
|
|
419
|
+
positionals;
|
|
420
|
+
candidates;
|
|
421
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
420
422
|
this.options = options;
|
|
423
|
+
this.positionals = positionals;
|
|
424
|
+
this.candidates = candidates;
|
|
421
425
|
}
|
|
422
426
|
}
|
|
423
427
|
var completion = { active: false };
|
|
@@ -460,8 +464,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
|
460
464
|
function optionRows(options, colors = paint(process3.stdout)) {
|
|
461
465
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
462
466
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
463
|
-
const
|
|
464
|
-
|
|
467
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
468
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
469
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
470
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
465
471
|
});
|
|
466
472
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
467
473
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
@@ -487,14 +493,13 @@ function applyOutput(color, plain, env = process3.env) {
|
|
|
487
493
|
function parse(args, usage, options, settings = {}) {
|
|
488
494
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
489
495
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
496
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
490
497
|
if (completion.active)
|
|
491
|
-
throw new Completing(
|
|
492
|
-
const
|
|
493
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
494
|
-
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
498
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
499
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
495
500
|
let parsed;
|
|
496
501
|
try {
|
|
497
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
502
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
498
503
|
} catch (error) {
|
|
499
504
|
const message = parseError(error);
|
|
500
505
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -502,12 +507,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
502
507
|
const values = parsed.values;
|
|
503
508
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
504
509
|
if (values.help === true) {
|
|
505
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
510
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
506
511
|
throw new HelpShown;
|
|
507
512
|
}
|
|
513
|
+
checkChoices(parsed.values, all);
|
|
514
|
+
checkConflicts(parsed.values, all);
|
|
508
515
|
if (settings.positionals !== undefined)
|
|
509
516
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
510
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
517
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
518
|
+
}
|
|
519
|
+
function splitRest(args, passes) {
|
|
520
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
521
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
522
|
+
}
|
|
523
|
+
function splitTrailing(args, options, count) {
|
|
524
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
525
|
+
let seen = 0;
|
|
526
|
+
if (count === 0)
|
|
527
|
+
return { own: args, rest: undefined };
|
|
528
|
+
for (let at = 0;at < args.length; at++) {
|
|
529
|
+
const word = args[at];
|
|
530
|
+
if (word === "--")
|
|
531
|
+
break;
|
|
532
|
+
if (word.startsWith("-")) {
|
|
533
|
+
if (takesValue(word))
|
|
534
|
+
at++;
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
seen++;
|
|
538
|
+
if (seen === count)
|
|
539
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
540
|
+
}
|
|
541
|
+
return { own: args, rest: undefined };
|
|
542
|
+
}
|
|
543
|
+
function listed(options, allowNegative) {
|
|
544
|
+
if (!allowNegative)
|
|
545
|
+
return options;
|
|
546
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
547
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
548
|
+
return [[name, option]];
|
|
549
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
function withBare(args, options) {
|
|
553
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
554
|
+
if (bare.size === 0)
|
|
555
|
+
return args;
|
|
556
|
+
const separator = args.indexOf("--");
|
|
557
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
558
|
+
return [...own.flatMap((arg, index) => {
|
|
559
|
+
const optional = bare.get(arg);
|
|
560
|
+
const next = own[index + 1];
|
|
561
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
562
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
563
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
564
|
+
}
|
|
565
|
+
function checkConflicts(values, options) {
|
|
566
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
567
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
568
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
569
|
+
if (other !== undefined)
|
|
570
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function checkChoices(values, options) {
|
|
574
|
+
for (const [name, option] of Object.entries(options)) {
|
|
575
|
+
if (option.choices === undefined)
|
|
576
|
+
continue;
|
|
577
|
+
const given = values[name];
|
|
578
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
579
|
+
if (typeof value === "string")
|
|
580
|
+
oneOf(value, name, option.choices);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function oneOf(value, name, choices) {
|
|
585
|
+
if (!choices.includes(value))
|
|
586
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
587
|
+
return value;
|
|
511
588
|
}
|
|
512
589
|
function checkPositionals(given, names) {
|
|
513
590
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -698,22 +775,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
698
775
|
}
|
|
699
776
|
var COMPLETE = "__complete";
|
|
700
777
|
var FILES = "__files__";
|
|
701
|
-
async function
|
|
778
|
+
async function completingOf(run) {
|
|
702
779
|
completion.active = true;
|
|
703
780
|
try {
|
|
704
781
|
await run([]);
|
|
705
782
|
} catch (error) {
|
|
706
783
|
if (error instanceof Completing)
|
|
707
|
-
return error
|
|
784
|
+
return error;
|
|
708
785
|
} finally {
|
|
709
786
|
completion.active = false;
|
|
710
787
|
}
|
|
711
|
-
return {};
|
|
788
|
+
return new Completing({});
|
|
789
|
+
}
|
|
790
|
+
function candidateLine(candidate) {
|
|
791
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
792
|
+
}
|
|
793
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
794
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
795
|
+
let index = 0;
|
|
796
|
+
let at = 0;
|
|
797
|
+
while (at < before.length) {
|
|
798
|
+
const word = before[at];
|
|
799
|
+
if (word === "--") {
|
|
800
|
+
index += before.length - at - 1;
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
if (!word.startsWith("-"))
|
|
804
|
+
index++;
|
|
805
|
+
else if (takesValue(word))
|
|
806
|
+
at++;
|
|
807
|
+
at++;
|
|
808
|
+
}
|
|
809
|
+
const last = positionals.at(-1);
|
|
810
|
+
if (index < positionals.length)
|
|
811
|
+
return positionals[index];
|
|
812
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
712
813
|
}
|
|
713
814
|
async function leafCandidates(run, words) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
815
|
+
const completing = await completingOf(run);
|
|
816
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
817
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
818
|
+
const flag = words.at(-2);
|
|
819
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
820
|
+
if (option?.type === "string") {
|
|
821
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
822
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
823
|
+
}
|
|
824
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
825
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
826
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
717
827
|
}
|
|
718
828
|
async function printCandidates(found) {
|
|
719
829
|
for (const line of await found)
|
|
@@ -736,7 +846,7 @@ async function runMain({ name, version, run, redact }, argv = process5.argv.slic
|
|
|
736
846
|
// ../kit/src/limit.ts
|
|
737
847
|
function limitOptions(fallback) {
|
|
738
848
|
return {
|
|
739
|
-
limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
849
|
+
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
740
850
|
full: { type: "boolean", description: "show every row" }
|
|
741
851
|
};
|
|
742
852
|
}
|
|
@@ -763,7 +873,7 @@ var {Glob } = globalThis.Bun;
|
|
|
763
873
|
var SESSION_FILES = new Glob("*.json");
|
|
764
874
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
765
875
|
// package.json
|
|
766
|
-
var version = "0.
|
|
876
|
+
var version = "0.6.0";
|
|
767
877
|
|
|
768
878
|
// src/files.ts
|
|
769
879
|
import { existsSync, readdirSync, statSync } from "fs";
|
package/dist/todo-scan.js
CHANGED
|
@@ -16,7 +16,7 @@ import process2 from "process";
|
|
|
16
16
|
// ../kit/src/style.ts
|
|
17
17
|
import process from "process";
|
|
18
18
|
|
|
19
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
19
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
20
20
|
function x(s) {
|
|
21
21
|
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
22
22
|
if (!/^[a-f0-9]+$/.test(r))
|
|
@@ -236,7 +236,7 @@ class e {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
239
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
240
240
|
var r = 39;
|
|
241
241
|
var o = 49;
|
|
242
242
|
var f2 = "\x1B[";
|
|
@@ -415,8 +415,12 @@ class HelpShown extends Exit {
|
|
|
415
415
|
|
|
416
416
|
class Completing {
|
|
417
417
|
options;
|
|
418
|
-
|
|
418
|
+
positionals;
|
|
419
|
+
candidates;
|
|
420
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
419
421
|
this.options = options;
|
|
422
|
+
this.positionals = positionals;
|
|
423
|
+
this.candidates = candidates;
|
|
420
424
|
}
|
|
421
425
|
}
|
|
422
426
|
var completion = { active: false };
|
|
@@ -459,8 +463,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
|
459
463
|
function optionRows(options, colors = paint(process3.stdout)) {
|
|
460
464
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
461
465
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
462
|
-
const
|
|
463
|
-
|
|
466
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
467
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
468
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
469
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
464
470
|
});
|
|
465
471
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
466
472
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
@@ -486,14 +492,13 @@ function applyOutput(color, plain, env = process3.env) {
|
|
|
486
492
|
function parse(args, usage, options, settings = {}) {
|
|
487
493
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
488
494
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
495
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
489
496
|
if (completion.active)
|
|
490
|
-
throw new Completing(
|
|
491
|
-
const
|
|
492
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
493
|
-
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
497
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
498
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
494
499
|
let parsed;
|
|
495
500
|
try {
|
|
496
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
501
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
497
502
|
} catch (error) {
|
|
498
503
|
const message = parseError(error);
|
|
499
504
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -501,12 +506,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
501
506
|
const values = parsed.values;
|
|
502
507
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
503
508
|
if (values.help === true) {
|
|
504
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
509
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
505
510
|
throw new HelpShown;
|
|
506
511
|
}
|
|
512
|
+
checkChoices(parsed.values, all);
|
|
513
|
+
checkConflicts(parsed.values, all);
|
|
507
514
|
if (settings.positionals !== undefined)
|
|
508
515
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
509
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
516
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
517
|
+
}
|
|
518
|
+
function splitRest(args, passes) {
|
|
519
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
520
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
521
|
+
}
|
|
522
|
+
function splitTrailing(args, options, count) {
|
|
523
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
524
|
+
let seen = 0;
|
|
525
|
+
if (count === 0)
|
|
526
|
+
return { own: args, rest: undefined };
|
|
527
|
+
for (let at = 0;at < args.length; at++) {
|
|
528
|
+
const word = args[at];
|
|
529
|
+
if (word === "--")
|
|
530
|
+
break;
|
|
531
|
+
if (word.startsWith("-")) {
|
|
532
|
+
if (takesValue(word))
|
|
533
|
+
at++;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
seen++;
|
|
537
|
+
if (seen === count)
|
|
538
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
539
|
+
}
|
|
540
|
+
return { own: args, rest: undefined };
|
|
541
|
+
}
|
|
542
|
+
function listed(options, allowNegative) {
|
|
543
|
+
if (!allowNegative)
|
|
544
|
+
return options;
|
|
545
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
546
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
547
|
+
return [[name, option]];
|
|
548
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
function withBare(args, options) {
|
|
552
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
553
|
+
if (bare.size === 0)
|
|
554
|
+
return args;
|
|
555
|
+
const separator = args.indexOf("--");
|
|
556
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
557
|
+
return [...own.flatMap((arg, index) => {
|
|
558
|
+
const optional = bare.get(arg);
|
|
559
|
+
const next = own[index + 1];
|
|
560
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
561
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
562
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
563
|
+
}
|
|
564
|
+
function checkConflicts(values, options) {
|
|
565
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
566
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
567
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
568
|
+
if (other !== undefined)
|
|
569
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function checkChoices(values, options) {
|
|
573
|
+
for (const [name, option] of Object.entries(options)) {
|
|
574
|
+
if (option.choices === undefined)
|
|
575
|
+
continue;
|
|
576
|
+
const given = values[name];
|
|
577
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
578
|
+
if (typeof value === "string")
|
|
579
|
+
oneOf(value, name, option.choices);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function oneOf(value, name, choices) {
|
|
584
|
+
if (!choices.includes(value))
|
|
585
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
586
|
+
return value;
|
|
510
587
|
}
|
|
511
588
|
function checkPositionals(given, names) {
|
|
512
589
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -697,22 +774,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
697
774
|
}
|
|
698
775
|
var COMPLETE = "__complete";
|
|
699
776
|
var FILES = "__files__";
|
|
700
|
-
async function
|
|
777
|
+
async function completingOf(run) {
|
|
701
778
|
completion.active = true;
|
|
702
779
|
try {
|
|
703
780
|
await run([]);
|
|
704
781
|
} catch (error) {
|
|
705
782
|
if (error instanceof Completing)
|
|
706
|
-
return error
|
|
783
|
+
return error;
|
|
707
784
|
} finally {
|
|
708
785
|
completion.active = false;
|
|
709
786
|
}
|
|
710
|
-
return {};
|
|
787
|
+
return new Completing({});
|
|
788
|
+
}
|
|
789
|
+
function candidateLine(candidate) {
|
|
790
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
791
|
+
}
|
|
792
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
793
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
794
|
+
let index = 0;
|
|
795
|
+
let at = 0;
|
|
796
|
+
while (at < before.length) {
|
|
797
|
+
const word = before[at];
|
|
798
|
+
if (word === "--") {
|
|
799
|
+
index += before.length - at - 1;
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
if (!word.startsWith("-"))
|
|
803
|
+
index++;
|
|
804
|
+
else if (takesValue(word))
|
|
805
|
+
at++;
|
|
806
|
+
at++;
|
|
807
|
+
}
|
|
808
|
+
const last = positionals.at(-1);
|
|
809
|
+
if (index < positionals.length)
|
|
810
|
+
return positionals[index];
|
|
811
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
711
812
|
}
|
|
712
813
|
async function leafCandidates(run, words) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
814
|
+
const completing = await completingOf(run);
|
|
815
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
816
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
817
|
+
const flag = words.at(-2);
|
|
818
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
819
|
+
if (option?.type === "string") {
|
|
820
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
821
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
822
|
+
}
|
|
823
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
824
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
825
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
716
826
|
}
|
|
717
827
|
async function printCandidates(found) {
|
|
718
828
|
for (const line of await found)
|
|
@@ -735,7 +845,7 @@ async function runMain({ name, version, run, redact }, argv = process5.argv.slic
|
|
|
735
845
|
// ../kit/src/limit.ts
|
|
736
846
|
function limitOptions(fallback) {
|
|
737
847
|
return {
|
|
738
|
-
limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
848
|
+
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
739
849
|
full: { type: "boolean", description: "show every row" }
|
|
740
850
|
};
|
|
741
851
|
}
|
|
@@ -762,7 +872,7 @@ var {Glob } = globalThis.Bun;
|
|
|
762
872
|
var SESSION_FILES = new Glob("*.json");
|
|
763
873
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
764
874
|
// package.json
|
|
765
|
-
var version = "0.
|
|
875
|
+
var version = "0.6.0";
|
|
766
876
|
|
|
767
877
|
// src/files.ts
|
|
768
878
|
import { existsSync, readdirSync, statSync } from "fs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-code",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
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.
|
|
44
|
+
"@kaynooo/cli-kit": "0.19.0"
|
|
45
45
|
}
|
|
46
46
|
}
|