@kaynooo/cli-dl 0.0.2 → 0.0.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.
Files changed (2) hide show
  1. package/dist/cli.js +180 -73
  2. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -29,8 +29,8 @@ var __esm = (fn, res, err) => () => {
29
29
  // ../kit/src/advisory.ts
30
30
  var init_advisory = () => {};
31
31
 
32
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
33
- function ko(t, e, r = "...") {
32
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
33
+ function Ao(t, e, r = "...") {
34
34
  let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
35
35
  if (t.length <= e)
36
36
  return t;
@@ -41,18 +41,18 @@ function ko(t, e, r = "...") {
41
41
  c = c.trimEnd();
42
42
  return s ? (c + n).slice(0, l) : c + n;
43
43
  }
44
- var N, Nt, Y, be, z;
45
- var init_chunk_rxztfxgv = __esm(() => {
44
+ var N, Nt, Y, be, W;
45
+ var init_chunk_rkhsft4a = __esm(() => {
46
46
  N = new Map;
47
47
  Nt = /\s+\S*$/;
48
48
  Y = /\s/;
49
49
  be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
50
- z = new Map;
50
+ W = new Map;
51
51
  });
52
52
 
53
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
53
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
54
54
  var init_text = __esm(() => {
55
- init_chunk_rxztfxgv();
55
+ init_chunk_rkhsft4a();
56
56
  });
57
57
 
58
58
  // ../kit/src/mode.ts
@@ -76,7 +76,7 @@ var init_mode = __esm(() => {
76
76
  AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
77
77
  });
78
78
 
79
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
79
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
80
80
  function b(r) {
81
81
  let e = r.startsWith("#") ? r.slice(1) : r;
82
82
  if (!G2.test(e))
@@ -100,7 +100,7 @@ function f(r, e = []) {
100
100
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
101
101
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
102
102
  return new Proxy(c, { get(t, i) {
103
- let a = B2[i];
103
+ let a = B[i];
104
104
  if (Array.isArray(a)) {
105
105
  let s = g.get(i);
106
106
  if (s === undefined)
@@ -123,10 +123,10 @@ function f(r, e = []) {
123
123
  function Fe(r = {}) {
124
124
  return f(r);
125
125
  }
126
- var G2, B2, h, o;
126
+ var G2, B, h, o;
127
127
  var init_chunk_x450vn3m = __esm(() => {
128
128
  G2 = /^[a-f0-9]+$/i;
129
- B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
129
+ B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
130
130
  let [l, n, c] = b(r);
131
131
  return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
132
132
  }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
@@ -134,7 +134,7 @@ var init_chunk_x450vn3m = __esm(() => {
134
134
  o = Fe();
135
135
  });
136
136
 
137
- // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
137
+ // ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
138
138
  var init_colors = __esm(() => {
139
139
  init_chunk_x450vn3m();
140
140
  });
@@ -458,7 +458,7 @@ function formatAge(date, now = Date.now()) {
458
458
  return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
459
459
  }
460
460
  function truncate(text, width) {
461
- return ko(text, width, { suffix: "\u2026", includeSuffix: true });
461
+ return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
462
462
  }
463
463
  function textWidth(text) {
464
464
  return Bun.stringWidth(text);
@@ -521,7 +521,27 @@ var init_format = __esm(() => {
521
521
  // ../kit/src/help.ts
522
522
  import process8 from "process";
523
523
  function usageLine(usage, colors = paint(process8.stdout)) {
524
- return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
524
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
525
+ `);
526
+ const blank = lines.indexOf("");
527
+ const synopses = blank === -1 ? lines : lines.slice(0, blank);
528
+ const details = blank === -1 ? [] : lines.slice(blank + 1);
529
+ const colon = synopses[0].indexOf(": ");
530
+ const inline = synopses[0].slice(colon + 2);
531
+ const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
532
+ if (colon !== -1)
533
+ synopses[0] = synopses[0].slice(0, colon);
534
+ const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
535
+ `)}`;
536
+ const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
537
+ const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
538
+ return [head, ...lead, ...rest].join(`
539
+ `);
540
+ }
541
+ function prose(line, colors) {
542
+ if (colors.cyan("x") === "x")
543
+ return line;
544
+ return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
525
545
  }
526
546
  function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
527
547
  return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
@@ -570,13 +590,14 @@ function optionRows(options, colors = paint(process8.stdout)) {
570
590
  const width = Math.max(0, ...rows.map((row) => row.width));
571
591
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
572
592
  }
573
- var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
593
+ var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
574
594
  var init_help = __esm(() => {
575
595
  init_mode();
576
596
  init_style();
577
597
  OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
578
598
  USAGE_PREFIX = /^usage:\s*/i;
579
599
  FULL_STOP = /\.$/;
600
+ PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
580
601
  });
581
602
 
582
603
  // ../kit/src/text.ts
@@ -803,7 +824,7 @@ function nearestOption(message, options, allowNegative) {
803
824
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
804
825
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
805
826
  }
806
- var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
827
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
807
828
  var init_args = __esm(() => {
808
829
  init_format();
809
830
  init_help();
@@ -811,14 +832,21 @@ var init_args = __esm(() => {
811
832
  init_help();
812
833
  init_input();
813
834
  DASHES = /^-+/;
835
+ EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
814
836
  Exit = class Exit extends Error {
815
837
  code;
816
838
  hint;
839
+ [EXIT] = true;
817
840
  constructor(message, code, hint) {
818
841
  super(message);
819
842
  this.code = code;
820
843
  this.hint = hint;
821
844
  }
845
+ static [Symbol.hasInstance](value) {
846
+ if (this !== Exit)
847
+ return Function.prototype[Symbol.hasInstance].call(this, value);
848
+ return typeof value === "object" && value !== null && value[EXIT] === true;
849
+ }
822
850
  };
823
851
  UsageError = class UsageError extends Exit {
824
852
  constructor(message, hint) {
@@ -919,10 +947,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
919
947
  }, print: (text) => void stream.write(`${text}
920
948
  `), stop: () => {
921
949
  return;
950
+ }, pause: () => () => {
951
+ return;
922
952
  } };
923
953
  const write = stream.write.bind(stream);
924
954
  let frame = 0;
925
955
  let drawn = false;
956
+ let paused = false;
957
+ let stopped = false;
926
958
  const columns = () => {
927
959
  const now = stream.getWindowSize?.()[0] ?? stream.columns;
928
960
  return now === undefined || now === 0 ? 80 : now;
@@ -933,6 +965,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
933
965
  drawn = false;
934
966
  };
935
967
  const draw = () => {
968
+ if (paused)
969
+ return;
936
970
  const width = columns() - 1;
937
971
  const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
938
972
  const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
@@ -944,16 +978,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
944
978
  `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
945
979
  drawn = true;
946
980
  };
947
- const timer = setInterval(draw, FRAME_MS);
981
+ let timer = setInterval(draw, FRAME_MS);
948
982
  stream.on?.("resize", draw);
949
- const restore = interceptOutput(clear);
950
- const release = swallowInput();
983
+ let restore = interceptOutput(clear);
984
+ let release = swallowInput();
951
985
  const onExit = () => {
952
986
  clear();
953
987
  release();
954
988
  };
955
989
  const signals = holdSignals(stop);
956
990
  function stop() {
991
+ stopped = true;
957
992
  clearInterval(timer);
958
993
  stream.off?.("resize", draw);
959
994
  clear();
@@ -962,6 +997,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
962
997
  process12.off("exit", onExit);
963
998
  signals.release();
964
999
  }
1000
+ function pause() {
1001
+ if (paused || stopped)
1002
+ return () => {
1003
+ return;
1004
+ };
1005
+ paused = true;
1006
+ clearInterval(timer);
1007
+ stream.off?.("resize", draw);
1008
+ clear();
1009
+ restore();
1010
+ release();
1011
+ return () => {
1012
+ if (!paused || stopped)
1013
+ return;
1014
+ paused = false;
1015
+ timer = setInterval(draw, FRAME_MS);
1016
+ timer.unref();
1017
+ stream.on?.("resize", draw);
1018
+ restore = interceptOutput(clear);
1019
+ release = swallowInput();
1020
+ draw();
1021
+ };
1022
+ }
965
1023
  timer.unref();
966
1024
  process12.on("exit", onExit);
967
1025
  return {
@@ -972,7 +1030,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
972
1030
  `);
973
1031
  draw();
974
1032
  },
975
- stop
1033
+ stop,
1034
+ pause
976
1035
  };
977
1036
  }
978
1037
  function progressLine(stream = process12.stderr, env = process12.env) {
@@ -997,6 +1056,7 @@ function progressLine(stream = process12.stderr, env = process12.env) {
997
1056
  }
998
1057
  },
999
1058
  stop: region.stop,
1059
+ pause: region.pause,
1000
1060
  done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
1001
1061
  failed: (text) => end(marked("problem", text, stream, undefined, env))
1002
1062
  };
@@ -1114,6 +1174,46 @@ var init_ci = __esm(() => {
1114
1174
  init_tool();
1115
1175
  });
1116
1176
 
1177
+ // ../kit/src/askpass.ts
1178
+ import process13 from "process";
1179
+ async function askpassClient(argv) {
1180
+ const socketPath = process13.env[SOCKET_VARIABLE];
1181
+ if (socketPath === undefined)
1182
+ return;
1183
+ const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
1184
+ const { promise, resolve } = Promise.withResolvers();
1185
+ let received = "";
1186
+ try {
1187
+ await Bun.connect({
1188
+ unix: socketPath,
1189
+ socket: {
1190
+ open: (socket) => void socket.write(`${JSON.stringify(request)}
1191
+ `),
1192
+ data: (_, chunk) => {
1193
+ received += chunk.toString();
1194
+ },
1195
+ close: () => resolve(received),
1196
+ error: () => resolve("")
1197
+ }
1198
+ });
1199
+ } catch {
1200
+ return 1;
1201
+ }
1202
+ const reply = await promise;
1203
+ if (reply === "")
1204
+ return 1;
1205
+ const { answer } = JSON.parse(reply);
1206
+ if (request.notice === true)
1207
+ return 0;
1208
+ if (answer === undefined)
1209
+ return 1;
1210
+ process13.stdout.write(`${answer}
1211
+ `);
1212
+ return 0;
1213
+ }
1214
+ var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1215
+ var init_askpass = () => {};
1216
+
1117
1217
  // ../kit/src/completions.ts
1118
1218
  function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1119
1219
  if (shell === "fish")
@@ -1175,16 +1275,16 @@ var init_completions = __esm(() => {
1175
1275
  });
1176
1276
 
1177
1277
  // ../kit/src/notify.ts
1178
- import process13 from "process";
1278
+ import process14 from "process";
1179
1279
  function base64(text) {
1180
1280
  return Buffer.from(text).toString("base64");
1181
1281
  }
1182
- function notification(title, body, env = process13.env) {
1183
- const id = `kit${process13.pid}`;
1282
+ function notification(title, body, env = process14.env) {
1283
+ const id = `kit${process14.pid}`;
1184
1284
  const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1185
1285
  return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1186
1286
  }
1187
- function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
1287
+ function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
1188
1288
  if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1189
1289
  return;
1190
1290
  stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
@@ -1205,18 +1305,18 @@ var init_logs = __esm(() => {
1205
1305
  import { appendFileSync, mkdirSync } from "fs";
1206
1306
  import { homedir as homedir3 } from "os";
1207
1307
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1208
- import process14 from "process";
1308
+ import process15 from "process";
1209
1309
  function noteUsageError(message) {
1210
1310
  usageError = message;
1211
1311
  }
1212
- function stateHome(env = process14.env) {
1312
+ function stateHome(env = process15.env) {
1213
1313
  const dir = env.XDG_STATE_HOME;
1214
1314
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1215
1315
  }
1216
- function usagePath(env = process14.env) {
1316
+ function usagePath(env = process15.env) {
1217
1317
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1218
1318
  }
1219
- function usageRecorded(env = process14.env) {
1319
+ function usageRecorded(env = process15.env) {
1220
1320
  const off = env.KAYNOOO_CLI_NO_USAGE;
1221
1321
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1222
1322
  }
@@ -1225,12 +1325,12 @@ function flagNames(argv) {
1225
1325
  const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
1226
1326
  return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
1227
1327
  }
1228
- function usageEntry(bin, command, argv, code, now = new Date) {
1328
+ function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
1229
1329
  const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
1230
1330
  usageError = undefined;
1231
- return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1331
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
1232
1332
  }
1233
- function recordUsage(entry, env = process14.env) {
1333
+ function recordUsage(entry, env = process15.env) {
1234
1334
  if (!usageRecorded(env))
1235
1335
  return;
1236
1336
  try {
@@ -1250,7 +1350,7 @@ var init_usage = __esm(() => {
1250
1350
  // ../kit/src/cli.ts
1251
1351
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
1252
1352
  import { dirname as dirname3, join as join5 } from "path";
1253
- import process15 from "process";
1353
+ import process16 from "process";
1254
1354
  async function commandRows(all, colors) {
1255
1355
  const commands = shown(all);
1256
1356
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1324,8 +1424,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1324
1424
  `);
1325
1425
  }
1326
1426
  function printError(prefix, message, hint, cause) {
1327
- const colors = paint(process15.stderr);
1328
- const styled = takesControlCodes(process15.stderr);
1427
+ const colors = paint(process16.stderr);
1428
+ const styled = takesControlCodes(process16.stderr);
1329
1429
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1330
1430
  const under = (label, text, tint) => text === undefined ? "" : `
1331
1431
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1368,11 +1468,11 @@ async function dispatch(level, typed, { version, redact }) {
1368
1468
  }
1369
1469
  }
1370
1470
  if (name === undefined && level.path.length > 1) {
1371
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
1471
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stderr));
1372
1472
  return 2;
1373
1473
  }
1374
1474
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1375
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
1475
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process16.stdout));
1376
1476
  return 0;
1377
1477
  }
1378
1478
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1515,6 +1615,9 @@ function packageVersion(entry = Bun.main) {
1515
1615
  }
1516
1616
  async function runCli(cli, argv = scriptArgs()) {
1517
1617
  const version = cli.version ?? packageVersion();
1618
+ const answered = await askpassClient(argv);
1619
+ if (answered !== undefined)
1620
+ return answered;
1518
1621
  if (argv[0] === COMPLETE)
1519
1622
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1520
1623
  if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
@@ -1525,7 +1628,7 @@ async function runCli(cli, argv = scriptArgs()) {
1525
1628
  notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1526
1629
  if (cli.usage !== false) {
1527
1630
  try {
1528
- recordUsage(usageEntry(cli.name, command, argv, code));
1631
+ recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
1529
1632
  } catch {}
1530
1633
  }
1531
1634
  return code;
@@ -1549,6 +1652,7 @@ var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__", CO
1549
1652
  var init_cli = __esm(() => {
1550
1653
  init_args();
1551
1654
  init_argv();
1655
+ init_askpass();
1552
1656
  init_completions();
1553
1657
  init_notify();
1554
1658
  init_style();
@@ -1676,8 +1780,8 @@ var init_src = __esm(() => {
1676
1780
  });
1677
1781
 
1678
1782
  // ../arc/src/proc.ts
1679
- import process17 from "process";
1680
- async function interactive(argv, cwd = process17.cwd()) {
1783
+ import process18 from "process";
1784
+ async function interactive(argv, cwd = process18.cwd()) {
1681
1785
  return Bun.spawn(argv, { cwd, stdin: "inherit", stdout: "inherit", stderr: "inherit" }).exited;
1682
1786
  }
1683
1787
  var init_proc = __esm(() => {
@@ -1685,7 +1789,7 @@ var init_proc = __esm(() => {
1685
1789
  });
1686
1790
 
1687
1791
  // ../arc/src/extract.ts
1688
- import { existsSync as existsSync3, rmSync, statSync as statSync2 } from "fs";
1792
+ import { existsSync as existsSync3, renameSync, rmSync, statSync as statSync2 } from "fs";
1689
1793
  import { basename, join as join6, resolve as resolve4 } from "path";
1690
1794
  function archiveSuffix(file) {
1691
1795
  return extractorOf(file)?.[0];
@@ -1693,14 +1797,14 @@ function archiveSuffix(file) {
1693
1797
  function extractorOf(file) {
1694
1798
  return EXTRACTORS.find(([suffix]) => file.toLowerCase().endsWith(suffix));
1695
1799
  }
1696
- async function extractArchive(file, cwd) {
1800
+ async function extractArchive(file, cwd, overwrite = false) {
1697
1801
  if (!existsSync3(file) || !statSync2(file).isFile())
1698
1802
  return fail(`'${file}' is not a file`, 1);
1699
1803
  const extractor = extractorOf(file);
1700
1804
  if (extractor === undefined)
1701
1805
  return fail(`'${file}' cannot be extracted: unknown extension`, 1);
1702
1806
  const [suffix, argvOf] = extractor;
1703
- const argv = argvOf(resolve4(file));
1807
+ const argv = argvOf(resolve4(file), overwrite);
1704
1808
  if (Bun.which(argv[0] ?? "") === null)
1705
1809
  return fail(`${argv[0]} is not on PATH`, 1);
1706
1810
  if (!LONE.has(suffix))
@@ -1709,34 +1813,39 @@ async function extractArchive(file, cwd) {
1709
1813
  if (name === "")
1710
1814
  return fail(`'${file}' has no name left once ${suffix} is taken off`, 1);
1711
1815
  const target = join6(cwd, name);
1712
- if (await Bun.spawn(argv, { stdin: "ignore", stdout: Bun.file(target), stderr: "inherit" }).exited === 0)
1816
+ if (existsSync3(target) && !overwrite)
1817
+ return fail(`'${target}' already exists, nothing written`, 1, "pass --overwrite to replace it");
1818
+ const partial = `${target}.arc-partial`;
1819
+ if (await Bun.spawn(argv, { stdin: "ignore", stdout: Bun.file(partial), stderr: "inherit" }).exited === 0) {
1820
+ renameSync(partial, target);
1713
1821
  return 0;
1714
- rmSync(target, { force: true });
1822
+ }
1823
+ rmSync(partial, { force: true });
1715
1824
  return 1;
1716
1825
  }
1717
- var EXTRACTORS, LONE;
1826
+ var keepOld = (overwrite) => overwrite ? [] : ["-k"], EXTRACTORS, LONE;
1718
1827
  var init_extract = __esm(() => {
1719
1828
  init_src();
1720
1829
  init_proc();
1721
1830
  EXTRACTORS = [
1722
- [".tar.bz2", (file) => ["tar", "xjf", file]],
1723
- [".tar.gz", (file) => ["tar", "xzf", file]],
1724
- [".tar.xz", (file) => ["tar", "xJf", file]],
1725
- [".tar.zst", (file) => ["tar", "--zstd", "-xf", file]],
1726
- [".tbz2", (file) => ["tar", "xjf", file]],
1727
- [".tgz", (file) => ["tar", "xzf", file]],
1728
- [".tar", (file) => ["tar", "xf", file]],
1729
- [".tbz", (file) => ["tar", "xjf", file]],
1730
- [".txz", (file) => ["tar", "xJf", file]],
1731
- [".tzst", (file) => ["tar", "--zstd", "-xf", file]],
1831
+ [".tar.bz2", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xjf", file]],
1832
+ [".tar.gz", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xzf", file]],
1833
+ [".tar.xz", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xJf", file]],
1834
+ [".tar.zst", (file, overwrite) => ["tar", ...keepOld(overwrite), "--zstd", "-xf", file]],
1835
+ [".tbz2", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xjf", file]],
1836
+ [".tgz", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xzf", file]],
1837
+ [".tar", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xf", file]],
1838
+ [".tbz", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xjf", file]],
1839
+ [".txz", (file, overwrite) => ["tar", ...keepOld(overwrite), "-xJf", file]],
1840
+ [".tzst", (file, overwrite) => ["tar", ...keepOld(overwrite), "--zstd", "-xf", file]],
1732
1841
  [".bz2", (file) => ["bunzip2", "-c", file]],
1733
1842
  [".gz", (file) => ["gunzip", "-c", file]],
1734
1843
  [".xz", (file) => ["xz", "-dc", file]],
1735
1844
  [".zst", (file) => ["zstd", "-dc", file]],
1736
- [".zip", (file) => ["unzip", file]],
1845
+ [".zip", (file, overwrite) => ["unzip", overwrite ? "-o" : "-n", file]],
1737
1846
  [".z", (file) => ["gzip", "-dc", file]],
1738
- [".rar", (file) => ["unrar", "x", file]],
1739
- [".7z", (file) => ["7z", "x", file]]
1847
+ [".rar", (file, overwrite) => ["unrar", "x", overwrite ? "-o+" : "-o-", file]],
1848
+ [".7z", (file, overwrite) => ["7z", "x", overwrite ? "-aoa" : "-aos", file]]
1740
1849
  ];
1741
1850
  LONE = new Set([".bz2", ".gz", ".xz", ".zst", ".z"]);
1742
1851
  });
@@ -1831,15 +1940,15 @@ var init_download = __esm(() => {
1831
1940
  });
1832
1941
 
1833
1942
  // src/install.ts
1834
- import { chmodSync, closeSync, copyFileSync, existsSync as existsSync5, mkdirSync as mkdirSync2, openSync, readSync, renameSync, statSync as statSync3 } from "fs";
1943
+ import { chmodSync, closeSync, copyFileSync, existsSync as existsSync5, mkdirSync as mkdirSync2, openSync, readSync, renameSync as renameSync2, statSync as statSync3 } from "fs";
1835
1944
  import { homedir as homedir4 } from "os";
1836
1945
  import { basename as basename3, delimiter, join as join8, relative } from "path";
1837
- import process18 from "process";
1946
+ import process19 from "process";
1838
1947
  function binDir() {
1839
1948
  return join8(homedir4(), ".local", "bin");
1840
1949
  }
1841
1950
  function binDirOnPath() {
1842
- return (process18.env.PATH ?? "").split(delimiter).includes(binDir());
1951
+ return (process19.env.PATH ?? "").split(delimiter).includes(binDir());
1843
1952
  }
1844
1953
  async function pickBinary(root, wanted) {
1845
1954
  const found = [];
@@ -1863,7 +1972,7 @@ function installBinary(source, name, force) {
1863
1972
  mkdirSync2(binDir(), { recursive: true });
1864
1973
  copyFileSync(source, `${target}.dl-tmp`);
1865
1974
  chmodSync(`${target}.dl-tmp`, 493);
1866
- renameSync(`${target}.dl-tmp`, target);
1975
+ renameSync2(`${target}.dl-tmp`, target);
1867
1976
  return target;
1868
1977
  }
1869
1978
  function isExecutable(file) {
@@ -1916,7 +2025,7 @@ var init_script = __esm(() => {
1916
2025
  });
1917
2026
 
1918
2027
  // src/state.ts
1919
- import { copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, rmSync as rmSync3, writeFileSync } from "fs";
2028
+ import { copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync as rmSync3, writeFileSync } from "fs";
1920
2029
  import { dirname as dirname4, join as join9 } from "path";
1921
2030
  function stateDir() {
1922
2031
  return join9(stateHome(), CLI_FOLDER, "dl");
@@ -1955,7 +2064,7 @@ function writeJson(path, value) {
1955
2064
  mkdirSync3(dirname4(path), { recursive: true });
1956
2065
  writeFileSync(`${path}.tmp`, `${JSON.stringify(value, null, 2)}
1957
2066
  `);
1958
- renameSync2(`${path}.tmp`, path);
2067
+ renameSync3(`${path}.tmp`, path);
1959
2068
  }
1960
2069
  var KEPT_TEXT;
1961
2070
  var init_state = __esm(() => {
@@ -2001,7 +2110,7 @@ __export(exports_get, {
2001
2110
  import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync4, mkdtempSync, rmSync as rmSync4 } from "fs";
2002
2111
  import { tmpdir } from "os";
2003
2112
  import { basename as basename5, extname, join as join10, resolve as resolve5 } from "path";
2004
- import process19 from "process";
2113
+ import process20 from "process";
2005
2114
  async function get(args) {
2006
2115
  const { values, positionals: [url], rest = [] } = parse(args, USAGE, OPTIONS, {
2007
2116
  positionals: ["<url>"],
@@ -2081,7 +2190,7 @@ async function fetchChecked(url, dir, created, checks) {
2081
2190
  async function diff(last, file, colored) {
2082
2191
  if (Bun.which("git") === null)
2083
2192
  return "";
2084
- const color = colored && takesControlCodes(process19.stdout) ? "--color=always" : "--no-color";
2193
+ const color = colored && takesControlCodes(process20.stdout) ? "--color=always" : "--no-color";
2085
2194
  const child = Bun.spawn(["git", "diff", "--no-index", color, "--", last, file.path], { stdin: "ignore", stdout: "pipe", stderr: "ignore" });
2086
2195
  const lines = (await child.stdout.text()).trimEnd().split(`
2087
2196
  `);
@@ -2140,11 +2249,9 @@ async function runScript(file, url, args) {
2140
2249
  }
2141
2250
  var USAGE = `dl [options] <url> [-- <script args>]: downloads a file into a new folder of its own, checks its sha256, then extracts it, installs it as a command or runs it as a script
2142
2251
 
2143
- Without -o the file lands in a new folder under the temp folder; with -o in that folder, created if missing, where nothing is overwritten.
2144
- Prints where the file went, its size, final URL, type and sha256, and how it compares with the last download of the same URL: a text file that changed since shows its diff.
2145
- --sha256 or --sums checks the file, which is deleted on a mismatch. An HTML page arriving where a file was expected fails, as does a download over --max-size.
2146
- --extract unpacks an archive into a new folder beside it, through arc's extractor. --bin installs the file, or the one executable its archive holds, in ~/.local/bin.
2147
- --exec lists what the script does (what it fetches, sudo, recursive removals, shell profiles and system folders it touches, code it runs in a shell, the variables it reads) and runs it only when --sha256 or --sums pins it, the content then being the one that was read, or with --yes. Arguments after -- go to the script.
2252
+ Without -o the file lands in a new folder under the temp folder. It prints where the file went, its size, final URL, type and sha256, and how it compares with the last download of the same URL (a changed text file shows its diff).
2253
+ An HTML page arriving where a file was expected fails, as does a download over --max-size.
2254
+ --exec lists what the script does and runs it only when --sha256 or --sums pins it, or with --yes; arguments after -- go to the script.
2148
2255
  --bin and --exec record what they installed or ran in the ledger dl ls lists.`, EXITS, OPTIONS, SHA256, DEFAULT_MAX_SIZE = "2G", HTML_EXTENSIONS, LINE_WIDTH = 120;
2149
2256
  var init_get = __esm(() => {
2150
2257
  init_extract();
@@ -2206,8 +2313,8 @@ var init_ls = __esm(() => {
2206
2313
 
2207
2314
  // src/cli.ts
2208
2315
  init_src();
2209
- import process20 from "process";
2210
- process20.exitCode = await runCli({
2316
+ import process21 from "process";
2317
+ process21.exitCode = await runCli({
2211
2318
  name: "dl",
2212
2319
  about: "downloads a file into a folder of its own, checks its sha256, then extracts it, installs it as a command or runs it as a script once it is pinned",
2213
2320
  replaces: "curl -fsSL <url> | sh, curl -LO then sha256sum -c by hand, and unpacking a release to copy its binary into ~/.local/bin",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-dl",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "dl: downloads a file into a folder of its own, verified by sha256, then extracts it, installs it as a command or runs it as a script once it is pinned; remembers every URL to show what changed.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "dl": "$npm_execpath src/cli.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-arc": "0.5.1",
39
- "@kaynooo/cli-kit": "0.41.0"
38
+ "@kaynooo/cli-arc": "0.6.1",
39
+ "@kaynooo/cli-kit": "0.45.1"
40
40
  }
41
41
  }