@kaynooo/cli-code 0.14.1 → 0.14.3
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 +3 -1
- package/dist/cli.js +127 -77
- package/dist/hotspots-cli.js +109 -57
- package/dist/peek-cli.js +110 -59
- package/dist/todo-scan-cli.js +102 -51
- package/package.json +2 -2
package/dist/peek-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/peek-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -126,7 +126,7 @@ function Fe(r = {}) {
|
|
|
126
126
|
var o = Fe();
|
|
127
127
|
|
|
128
128
|
// ../kit/src/theme.ts
|
|
129
|
-
import { existsSync as
|
|
129
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
130
130
|
import { homedir as homedir2 } from "os";
|
|
131
131
|
import { join as join3, resolve as resolve2 } from "path";
|
|
132
132
|
import process5 from "process";
|
|
@@ -147,6 +147,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// ../kit/src/user-config.ts
|
|
150
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
150
151
|
import { homedir } from "os";
|
|
151
152
|
import { join as join2 } from "path";
|
|
152
153
|
import process4 from "process";
|
|
@@ -157,6 +158,28 @@ function configBase(where = {}) {
|
|
|
157
158
|
function userConfigPath(bin, where = {}) {
|
|
158
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
159
160
|
}
|
|
161
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
162
|
+
const current = userConfigPath(bin, where);
|
|
163
|
+
if (existsSync2(current))
|
|
164
|
+
return current;
|
|
165
|
+
const base = configBase(where);
|
|
166
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
167
|
+
}
|
|
168
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
169
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return {};
|
|
172
|
+
try {
|
|
173
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
174
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
175
|
+
} catch {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
180
|
+
const value = readUserConfig(bin, where, legacy)[key];
|
|
181
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
182
|
+
}
|
|
160
183
|
|
|
161
184
|
// ../kit/src/theme.ts
|
|
162
185
|
var ENDS = new Map;
|
|
@@ -223,7 +246,7 @@ function readThemeFile(path, warn) {
|
|
|
223
246
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
224
247
|
return;
|
|
225
248
|
}
|
|
226
|
-
const parsed = JSON.parse(
|
|
249
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
227
250
|
if (isRecord(parsed))
|
|
228
251
|
return parsed;
|
|
229
252
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -289,7 +312,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
314
|
function endsWalk(home) {
|
|
292
|
-
return (dir) => dir === resolve2(home) ||
|
|
315
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
293
316
|
}
|
|
294
317
|
var warned = new Set;
|
|
295
318
|
function warnOnce(message) {
|
|
@@ -465,18 +488,14 @@ var FULL_STOP = /\.$/;
|
|
|
465
488
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
466
489
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
467
490
|
}
|
|
468
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
469
|
-
return [usageLine(usage, colors),
|
|
491
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
492
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
470
493
|
`);
|
|
471
494
|
}
|
|
472
495
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
473
496
|
if (exits.length === 0)
|
|
474
497
|
return [];
|
|
475
|
-
|
|
476
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
477
|
-
}
|
|
478
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
479
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
498
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
480
499
|
}
|
|
481
500
|
function wantsHelpJson(env = process8.env) {
|
|
482
501
|
return env.KIT_HELP === "json";
|
|
@@ -777,9 +796,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
777
796
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
778
797
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
779
798
|
}
|
|
799
|
+
// ../kit/src/argv.ts
|
|
800
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
801
|
+
import { resolve as resolve4 } from "path";
|
|
802
|
+
import process10 from "process";
|
|
803
|
+
function commandLine() {
|
|
804
|
+
try {
|
|
805
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
806
|
+
} catch {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function realPath(word) {
|
|
811
|
+
try {
|
|
812
|
+
return realpathSync(resolve4(word));
|
|
813
|
+
} catch {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
818
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
819
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve4(word) === script || realPath(word) === target));
|
|
820
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
821
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
822
|
+
}
|
|
780
823
|
// ../kit/src/process.ts
|
|
781
824
|
import { constants } from "os";
|
|
782
|
-
import
|
|
825
|
+
import process11 from "process";
|
|
783
826
|
var KILL_GRACE_MS = 2000;
|
|
784
827
|
function exitCodeOf(code, signal) {
|
|
785
828
|
if (code !== null)
|
|
@@ -799,7 +842,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
799
842
|
return;
|
|
800
843
|
try {
|
|
801
844
|
if (grouped)
|
|
802
|
-
|
|
845
|
+
process11.kill(-proc.pid, killing);
|
|
803
846
|
else
|
|
804
847
|
proc.kill(killing);
|
|
805
848
|
} catch {}
|
|
@@ -873,15 +916,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
873
916
|
var RESET_STYLE = `${ESC}[0m`;
|
|
874
917
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
875
918
|
// ../kit/src/cli.ts
|
|
876
|
-
import { readFileSync as
|
|
919
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
877
920
|
import { dirname as dirname3, join as join5 } from "path";
|
|
878
|
-
import
|
|
921
|
+
import process13 from "process";
|
|
879
922
|
|
|
880
923
|
// ../kit/src/usage.ts
|
|
881
924
|
import { appendFileSync, mkdirSync } from "fs";
|
|
882
925
|
import { homedir as homedir3 } from "os";
|
|
883
926
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
884
|
-
import
|
|
927
|
+
import process12 from "process";
|
|
885
928
|
|
|
886
929
|
// ../kit/src/logs.ts
|
|
887
930
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -895,14 +938,14 @@ var usageError;
|
|
|
895
938
|
function noteUsageError(message) {
|
|
896
939
|
usageError = message;
|
|
897
940
|
}
|
|
898
|
-
function stateHome(env =
|
|
941
|
+
function stateHome(env = process12.env) {
|
|
899
942
|
const dir = env.XDG_STATE_HOME;
|
|
900
943
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
901
944
|
}
|
|
902
|
-
function usagePath(env =
|
|
945
|
+
function usagePath(env = process12.env) {
|
|
903
946
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
904
947
|
}
|
|
905
|
-
function usageRecorded(env =
|
|
948
|
+
function usageRecorded(env = process12.env) {
|
|
906
949
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
907
950
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
908
951
|
}
|
|
@@ -916,7 +959,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
916
959
|
usageError = undefined;
|
|
917
960
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
918
961
|
}
|
|
919
|
-
function recordUsage(entry, env =
|
|
962
|
+
function recordUsage(entry, env = process12.env) {
|
|
920
963
|
if (!usageRecorded(env))
|
|
921
964
|
return;
|
|
922
965
|
try {
|
|
@@ -993,7 +1036,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
993
1036
|
header(colors, summary),
|
|
994
1037
|
"",
|
|
995
1038
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
996
|
-
...replacesRows(replaces, colors),
|
|
997
1039
|
"",
|
|
998
1040
|
...await commandRows(commands, colors),
|
|
999
1041
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1007,8 +1049,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1007
1049
|
`);
|
|
1008
1050
|
}
|
|
1009
1051
|
function printError(prefix, message, hint, cause) {
|
|
1010
|
-
const colors = paint(
|
|
1011
|
-
const styled = takesControlCodes(
|
|
1052
|
+
const colors = paint(process13.stderr);
|
|
1053
|
+
const styled = takesControlCodes(process13.stderr);
|
|
1012
1054
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1013
1055
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1014
1056
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1051,11 +1093,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1051
1093
|
}
|
|
1052
1094
|
}
|
|
1053
1095
|
if (name === undefined && level.path.length > 1) {
|
|
1054
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1096
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
1055
1097
|
return 2;
|
|
1056
1098
|
}
|
|
1057
1099
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1058
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1100
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
1059
1101
|
return 0;
|
|
1060
1102
|
}
|
|
1061
1103
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1111,24 +1153,24 @@ function candidateLine(candidate) {
|
|
|
1111
1153
|
}
|
|
1112
1154
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1113
1155
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1114
|
-
|
|
1156
|
+
const typed = [];
|
|
1115
1157
|
let at = 0;
|
|
1116
1158
|
while (at < before.length) {
|
|
1117
1159
|
const word = before[at];
|
|
1118
1160
|
if (word === "--") {
|
|
1119
|
-
|
|
1161
|
+
typed.push(...before.slice(at + 1));
|
|
1120
1162
|
break;
|
|
1121
1163
|
}
|
|
1122
1164
|
if (!word.startsWith("-"))
|
|
1123
|
-
|
|
1165
|
+
typed.push(word);
|
|
1124
1166
|
else if (takesValue(word))
|
|
1125
1167
|
at++;
|
|
1126
1168
|
at++;
|
|
1127
1169
|
}
|
|
1128
1170
|
const last = positionals.at(-1);
|
|
1129
|
-
if (
|
|
1130
|
-
return positionals[
|
|
1131
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1171
|
+
if (typed.length < positionals.length)
|
|
1172
|
+
return { name: positionals[typed.length], typed };
|
|
1173
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1132
1174
|
}
|
|
1133
1175
|
async function leafCandidates(run, words) {
|
|
1134
1176
|
const completing = await completingOf(run);
|
|
@@ -1136,12 +1178,12 @@ async function leafCandidates(run, words) {
|
|
|
1136
1178
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1137
1179
|
const flag = words.at(-2);
|
|
1138
1180
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1181
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1139
1182
|
if (option?.type === "string") {
|
|
1140
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1183
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1141
1184
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1142
1185
|
}
|
|
1143
|
-
const
|
|
1144
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1186
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1145
1187
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1146
1188
|
}
|
|
1147
1189
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1172,9 +1214,13 @@ async function printCandidates(found) {
|
|
|
1172
1214
|
return 0;
|
|
1173
1215
|
}
|
|
1174
1216
|
function packageVersion(entry = Bun.main) {
|
|
1175
|
-
|
|
1217
|
+
let resolved = entry;
|
|
1218
|
+
try {
|
|
1219
|
+
resolved = realpathSync2(entry);
|
|
1220
|
+
} catch {}
|
|
1221
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1176
1222
|
try {
|
|
1177
|
-
const { version } = JSON.parse(
|
|
1223
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1178
1224
|
if (typeof version === "string")
|
|
1179
1225
|
return version;
|
|
1180
1226
|
} catch {}
|
|
@@ -1182,7 +1228,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1182
1228
|
return "0.0.0";
|
|
1183
1229
|
}
|
|
1184
1230
|
}
|
|
1185
|
-
async function runCli(cli, argv =
|
|
1231
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1186
1232
|
const version = cli.version ?? packageVersion();
|
|
1187
1233
|
if (argv[0] === COMPLETE)
|
|
1188
1234
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1209,7 +1255,7 @@ function commandPath(scope, argv) {
|
|
|
1209
1255
|
}
|
|
1210
1256
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1211
1257
|
}
|
|
1212
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1258
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1213
1259
|
if (argv[0] === COMPLETE)
|
|
1214
1260
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1215
1261
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1231,6 +1277,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1231
1277
|
}
|
|
1232
1278
|
// ../kit/src/folders.ts
|
|
1233
1279
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1280
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1281
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1282
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1283
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1284
|
+
}
|
|
1234
1285
|
// ../kit/src/limit.ts
|
|
1235
1286
|
function limitOptions(fallback) {
|
|
1236
1287
|
return {
|
|
@@ -1259,16 +1310,16 @@ var {Glob } = globalThis.Bun;
|
|
|
1259
1310
|
var SESSION_FILES = new Glob("*.json");
|
|
1260
1311
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1261
1312
|
// src/peek.ts
|
|
1262
|
-
import { realpathSync as
|
|
1263
|
-
import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as
|
|
1264
|
-
import
|
|
1313
|
+
import { realpathSync as realpathSync3 } from "fs";
|
|
1314
|
+
import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve5, sep } from "path";
|
|
1315
|
+
import process15 from "process";
|
|
1265
1316
|
|
|
1266
1317
|
// src/files.ts
|
|
1267
|
-
import { existsSync as
|
|
1318
|
+
import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
1268
1319
|
import { join as join6, relative } from "path";
|
|
1269
1320
|
var MAX_BYTES = 2000000;
|
|
1270
1321
|
var SNIFF_BYTES = 8000;
|
|
1271
|
-
function walk(dir, found) {
|
|
1322
|
+
function walk(dir, found, ignored) {
|
|
1272
1323
|
let entries;
|
|
1273
1324
|
try {
|
|
1274
1325
|
entries = readdirSync(dir, { withFileTypes: true });
|
|
@@ -1276,10 +1327,10 @@ function walk(dir, found) {
|
|
|
1276
1327
|
return found;
|
|
1277
1328
|
}
|
|
1278
1329
|
for (const entry of entries) {
|
|
1279
|
-
if (entry.name.startsWith(".") ||
|
|
1330
|
+
if (entry.name.startsWith(".") || ignored.has(entry.name))
|
|
1280
1331
|
continue;
|
|
1281
1332
|
if (entry.isDirectory())
|
|
1282
|
-
walk(join6(dir, entry.name), found);
|
|
1333
|
+
walk(join6(dir, entry.name), found, ignored);
|
|
1283
1334
|
else if (entry.isFile())
|
|
1284
1335
|
found.push(join6(dir, entry.name));
|
|
1285
1336
|
}
|
|
@@ -1288,9 +1339,10 @@ function walk(dir, found) {
|
|
|
1288
1339
|
async function listFiles(paths, cwd) {
|
|
1289
1340
|
const listed = await runCommand(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...paths], { cwd });
|
|
1290
1341
|
if (listed.code === 0)
|
|
1291
|
-
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" &&
|
|
1342
|
+
return [...new Set(listed.text.split("\x00"))].filter((path) => path !== "" && existsSync4(join6(cwd, path))).sort();
|
|
1292
1343
|
const roots = paths.length === 0 ? [cwd] : paths.map((path) => join6(cwd, path));
|
|
1293
|
-
|
|
1344
|
+
const ignored = ignoredFolders();
|
|
1345
|
+
return roots.flatMap((root) => statSync2(root, { throwIfNoEntry: false })?.isFile() === true ? [root] : walk(root, [], ignored)).map((path) => relative(cwd, path)).sort();
|
|
1294
1346
|
}
|
|
1295
1347
|
async function readText(path) {
|
|
1296
1348
|
const file = Bun.file(path);
|
|
@@ -1486,9 +1538,8 @@ peek --around <regex> [-C 3] [path...] the lines around each match, overlapping
|
|
|
1486
1538
|
<output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1487
1539
|
The paths default to the files git keeps here (.gitignore holds).
|
|
1488
1540
|
--refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
|
|
1489
|
-
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given
|
|
1490
|
-
|
|
1491
|
-
Exits 0 when it printed something, 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.`;
|
|
1541
|
+
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
|
|
1542
|
+
var EXITS = [[0, "it printed something"], [1, "nothing is found, a file cannot be read or a span starts past the end"], [2, "a usage error or a path outside the repository"]];
|
|
1492
1543
|
var REFS_LIMIT = 100;
|
|
1493
1544
|
var AROUND_LIMIT = 20;
|
|
1494
1545
|
var PARENT = `..${sep}`;
|
|
@@ -1509,13 +1560,13 @@ function cut(text) {
|
|
|
1509
1560
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1510
1561
|
}
|
|
1511
1562
|
async function readableRoot() {
|
|
1512
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1513
|
-
return
|
|
1563
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process15.cwd() });
|
|
1564
|
+
return realpathSync3(ran.code === 0 ? ran.text.trim() : process15.cwd());
|
|
1514
1565
|
}
|
|
1515
1566
|
async function isOutside(path) {
|
|
1516
1567
|
let real;
|
|
1517
1568
|
try {
|
|
1518
|
-
real =
|
|
1569
|
+
real = realpathSync3(resolve5(process15.cwd(), path));
|
|
1519
1570
|
} catch {
|
|
1520
1571
|
return false;
|
|
1521
1572
|
}
|
|
@@ -1529,7 +1580,7 @@ async function checkInside(path) {
|
|
|
1529
1580
|
async function pipedSpans(text, context) {
|
|
1530
1581
|
const spans = [];
|
|
1531
1582
|
for (const [path, numbers] of locations(text)) {
|
|
1532
|
-
const source = await isOutside(path) ? undefined : await readText(
|
|
1583
|
+
const source = await isOutside(path) ? undefined : await readText(resolve5(process15.cwd(), path));
|
|
1533
1584
|
if (source !== undefined)
|
|
1534
1585
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1535
1586
|
`).length, numbers, context));
|
|
@@ -1538,7 +1589,7 @@ async function pipedSpans(text, context) {
|
|
|
1538
1589
|
}
|
|
1539
1590
|
async function textOf(path) {
|
|
1540
1591
|
await checkInside(path);
|
|
1541
|
-
const text = await readText(
|
|
1592
|
+
const text = await readText(resolve5(process15.cwd(), path));
|
|
1542
1593
|
if (text === undefined)
|
|
1543
1594
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1544
1595
|
return text;
|
|
@@ -1596,8 +1647,8 @@ async function spanOf(target) {
|
|
|
1596
1647
|
async function* sources(paths) {
|
|
1597
1648
|
for (const path of paths)
|
|
1598
1649
|
await checkInside(path);
|
|
1599
|
-
for (const path of await listFiles(paths,
|
|
1600
|
-
const text = await readText(join7(
|
|
1650
|
+
for (const path of await listFiles(paths, process15.cwd())) {
|
|
1651
|
+
const text = await readText(join7(process15.cwd(), path));
|
|
1601
1652
|
if (text !== undefined)
|
|
1602
1653
|
yield { path, text };
|
|
1603
1654
|
}
|
|
@@ -1621,7 +1672,7 @@ async function definitionsOf(symbols, paths) {
|
|
|
1621
1672
|
return [...found.values()].flat();
|
|
1622
1673
|
}
|
|
1623
1674
|
async function peek(args) {
|
|
1624
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
1675
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
1625
1676
|
const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1626
1677
|
const json = values.json === true;
|
|
1627
1678
|
if (values["defs-first"] === true && values.refs === undefined)
|
|
@@ -1697,4 +1748,4 @@ async function peek(args) {
|
|
|
1697
1748
|
}
|
|
1698
1749
|
|
|
1699
1750
|
// src/peek-cli.ts
|
|
1700
|
-
|
|
1751
|
+
process16.exitCode = await runMain({ name: "peek", run: peek });
|