@kaynooo/cli-git 0.5.2 → 0.7.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/dist/gc.js CHANGED
@@ -2,14 +2,13 @@
2
2
  // @bun
3
3
 
4
4
  // src/gc.ts
5
- import process8 from "process";
6
-
5
+ import process9 from "process";
7
6
  // ../kit/src/args.ts
8
- import process3 from "process";
7
+ import process4 from "process";
9
8
  import { parseArgs } from "util";
10
9
 
11
10
  // ../kit/src/style.ts
12
- import process from "process";
11
+ import process2 from "process";
13
12
 
14
13
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
15
14
  function x(s) {
@@ -273,10 +272,10 @@ function le(i = {}) {
273
272
  var t = le();
274
273
 
275
274
  // ../kit/src/style.ts
276
- function takesControlCodes(stream, env = process.env) {
275
+ function takesControlCodes(stream, env = process2.env) {
277
276
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
278
277
  }
279
- function paint(stream, env = process.env) {
278
+ function paint(stream, env = process2.env) {
280
279
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
281
280
  }
282
281
  var STATUSES = {
@@ -299,24 +298,30 @@ function printJson(value) {
299
298
  }
300
299
 
301
300
  // ../kit/src/help.ts
302
- import process2 from "process";
301
+ import process3 from "process";
303
302
  var OPTIONAL = /\[[^\]]+\]/g;
304
303
  var USAGE_PREFIX = /^usage:\s*/i;
305
304
  var FULL_STOP = /\.$/;
306
- function usageLine(usage, colors = paint(process2.stdout)) {
305
+ function usageLine(usage, colors = paint(process3.stdout)) {
307
306
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
308
307
  }
309
- function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
310
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
308
+ function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
309
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
311
310
  `);
312
311
  }
313
- function replacesRows(replaces, colors = paint(process2.stdout)) {
312
+ function exitRows(exits, colors = paint(process3.stdout)) {
313
+ if (exits.length === 0)
314
+ return [];
315
+ const width = Math.max(...exits.map(([code]) => String(code).length));
316
+ return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
317
+ }
318
+ function replacesRows(replaces, colors = paint(process3.stdout)) {
314
319
  return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
315
320
  }
316
- function wantsHelpJson(env = process2.env) {
321
+ function wantsHelpJson(env = process3.env) {
317
322
  return env.KIT_HELP === "json";
318
323
  }
319
- function description(usage, { examples = [], replaces } = {}) {
324
+ function description(usage, { examples = [], replaces, exits } = {}, options) {
320
325
  const lines = usage.replace(USAGE_PREFIX, "").split(`
321
326
  `);
322
327
  const first = lines[0];
@@ -327,15 +332,17 @@ function description(usage, { examples = [], replaces } = {}) {
327
332
  synopsis: colon === -1 ? first : first.slice(0, colon),
328
333
  summary: colon === -1 ? fallback : first.slice(colon + 2),
329
334
  ...replaces === undefined ? {} : { replaces },
330
- examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
335
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
336
+ ...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
337
+ ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
331
338
  };
332
339
  }
333
- function exampleRows(examples, colors = paint(process2.stdout)) {
340
+ function exampleRows(examples, colors = paint(process3.stdout)) {
334
341
  if (examples.length === 0)
335
342
  return [];
336
343
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
337
344
  }
338
- function optionRows(options, colors = paint(process2.stdout)) {
345
+ function optionRows(options, colors = paint(process3.stdout)) {
339
346
  const rows = Object.entries(options).map(([name, option]) => {
340
347
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
341
348
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -426,7 +433,7 @@ var OUTPUT_OPTIONS = {
426
433
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
427
434
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
428
435
  };
429
- function applyOutput(color, plain, env = process3.env) {
436
+ function applyOutput(color, plain, env = process4.env) {
430
437
  const when = plain === true ? "never" : color ?? "auto";
431
438
  if (when === "auto")
432
439
  return;
@@ -449,7 +456,7 @@ function parse(args, usage, options, settings = {}) {
449
456
  const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
450
457
  let parsed;
451
458
  try {
452
- parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
459
+ parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
453
460
  } catch (error) {
454
461
  const message = parseError(error);
455
462
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -457,7 +464,7 @@ function parse(args, usage, options, settings = {}) {
457
464
  const values = parsed.values;
458
465
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
459
466
  if (values.help === true) {
460
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
467
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
461
468
  throw new HelpShown;
462
469
  }
463
470
  checkChoices(parsed.values, all);
@@ -499,6 +506,18 @@ function listed(options, allowNegative) {
499
506
  return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
500
507
  }));
501
508
  }
509
+ function withAliases(args, options) {
510
+ const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
511
+ if (named.size === 0)
512
+ return args;
513
+ const separator = args.indexOf("--");
514
+ const own = separator === -1 ? args : args.slice(0, separator);
515
+ return [...own.map((arg) => {
516
+ const at = arg.indexOf("=");
517
+ const current = named.get(at === -1 ? arg : arg.slice(0, at));
518
+ return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
519
+ }), ...separator === -1 ? [] : args.slice(separator)];
520
+ }
502
521
  function withBare(args, options) {
503
522
  const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
504
523
  if (bare.size === 0)
@@ -585,7 +604,7 @@ function nearestOption(message, options, allowNegative) {
585
604
  }
586
605
  // ../kit/src/process.ts
587
606
  import { constants } from "os";
588
- import process4 from "process";
607
+ import process5 from "process";
589
608
  var KILL_GRACE_MS = 2000;
590
609
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
591
610
  function exitCodeOf(code, signal) {
@@ -607,7 +626,7 @@ function holdSignals(cleanup) {
607
626
  },
608
627
  release: () => {
609
628
  for (const signal of SIGNALS)
610
- process4.off(signal, onSignal);
629
+ process5.off(signal, onSignal);
611
630
  }
612
631
  };
613
632
  function onSignal(signal) {
@@ -620,10 +639,10 @@ function holdSignals(cleanup) {
620
639
  return;
621
640
  held.release();
622
641
  cleanup(signal);
623
- process4.kill(process4.pid, signal);
642
+ process5.kill(process5.pid, signal);
624
643
  }
625
644
  for (const signal of SIGNALS)
626
- process4.on(signal, onSignal);
645
+ process5.on(signal, onSignal);
627
646
  return held;
628
647
  }
629
648
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -637,7 +656,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
637
656
  return;
638
657
  try {
639
658
  if (grouped)
640
- process4.kill(-proc.pid, killing);
659
+ process5.kill(-proc.pid, killing);
641
660
  else
642
661
  proc.kill(killing);
643
662
  } catch {}
@@ -711,13 +730,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
711
730
  var RESET_STYLE = `${ESC}[0m`;
712
731
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
713
732
  // ../kit/src/cli.ts
714
- import process6 from "process";
733
+ import { readFileSync, realpathSync } from "fs";
734
+ import { dirname as dirname2, join as join2 } from "path";
735
+ import process7 from "process";
715
736
 
716
737
  // ../kit/src/usage.ts
717
738
  import { appendFileSync, mkdirSync } from "fs";
718
739
  import { homedir } from "os";
719
740
  import { dirname, isAbsolute, join } from "path";
720
- import process5 from "process";
741
+ import process6 from "process";
721
742
 
722
743
  // ../kit/src/logs.ts
723
744
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -731,14 +752,14 @@ var usageError;
731
752
  function noteUsageError(message) {
732
753
  usageError = message;
733
754
  }
734
- function stateHome(env = process5.env) {
755
+ function stateHome(env = process6.env) {
735
756
  const dir = env.XDG_STATE_HOME;
736
757
  return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
737
758
  }
738
- function usagePath(env = process5.env) {
759
+ function usagePath(env = process6.env) {
739
760
  return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
740
761
  }
741
- function usageRecorded(env = process5.env) {
762
+ function usageRecorded(env = process6.env) {
742
763
  const off = env.KAYNOOO_CLI_NO_USAGE;
743
764
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
744
765
  }
@@ -752,7 +773,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
752
773
  usageError = undefined;
753
774
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
754
775
  }
755
- function recordUsage(entry, env = process5.env) {
776
+ function recordUsage(entry, env = process6.env) {
756
777
  if (!usageRecorded(env))
757
778
  return;
758
779
  try {
@@ -770,8 +791,8 @@ var LEVEL_OPTIONS = {
770
791
  };
771
792
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
772
793
  function printError(prefix, message, hint, cause) {
773
- const colors = paint(process6.stderr);
774
- const styled = takesControlCodes(process6.stderr);
794
+ const colors = paint(process7.stderr);
795
+ const styled = takesControlCodes(process7.stderr);
775
796
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
776
797
  const under = (label, text, tint) => text === undefined ? "" : `
777
798
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -856,11 +877,22 @@ async function printCandidates(found) {
856
877
  console.log(line);
857
878
  return 0;
858
879
  }
859
- async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
880
+ function packageVersion(entry = Bun.main) {
881
+ for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
882
+ try {
883
+ const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
884
+ if (typeof version === "string")
885
+ return version;
886
+ } catch {}
887
+ if (dirname2(dir) === dir)
888
+ return "0.0.0";
889
+ }
890
+ }
891
+ async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
860
892
  if (argv[0] === COMPLETE)
861
893
  return printCandidates(leafCandidates(run, argv.slice(1)));
862
894
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
863
- console.log(version);
895
+ console.log(version ?? packageVersion());
864
896
  return 0;
865
897
  }
866
898
  let code;
@@ -869,8 +901,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process6.ar
869
901
  } catch (error) {
870
902
  code = reportThrown(name, error, redact, wantsJson(argv));
871
903
  }
872
- if (usage !== false)
873
- recordUsage(usageEntry(name, undefined, argv, code));
904
+ if (usage !== false) {
905
+ try {
906
+ recordUsage(usageEntry(name, undefined, argv, code));
907
+ } catch {}
908
+ }
874
909
  return code;
875
910
  }
876
911
  // ../kit/src/secrets.ts
@@ -879,9 +914,6 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
879
914
  var {Glob } = globalThis.Bun;
880
915
  var SESSION_FILES = new Glob("*.json");
881
916
  var ACCOUNT_DIRS = new Glob("*/sessions");
882
- // package.json
883
- var version = "0.5.2";
884
-
885
917
  // src/git.ts
886
918
  async function git2(args, env) {
887
919
  const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
@@ -948,11 +980,12 @@ var USAGE = `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...: commit
948
980
  Exits 0 when it committed, 1 when the message is refused or git fails (nothing is committed), 2 on a usage error or outside a git repository, 128 plus the signal when interrupted.`;
949
981
  var OPTIONS = {
950
982
  message: { type: "string", short: "m", multiple: true, description: "a line on what changed, at most two" },
951
- ticket: { type: "string", multiple: true, description: "a ticket line, `#<n> - <title>` (`owner/repo#<n> - <title>` across repositories) copied verbatim from the ticket" }
983
+ ticket: { type: "string", multiple: true, description: "a ticket line, `#<n> - <title>` (`owner/repo#<n> - <title>` across repositories) copied verbatim from the ticket" },
984
+ json: jsonOption("{sha, subject, files: [{status, path, from?}]} of the commit")
952
985
  };
953
986
  var RENAME = /^[RC]\d*$/;
954
987
  var NOT_A_REPOSITORY = /not a git repository/i;
955
- var LITERAL = { ...process8.env, GIT_LITERAL_PATHSPECS: "1" };
988
+ var LITERAL = { ...process9.env, GIT_LITERAL_PATHSPECS: "1" };
956
989
  function messageOf(title, lines, tickets) {
957
990
  return [title, lines.join(`
958
991
  `), tickets.join(`
@@ -1025,18 +1058,29 @@ ${USAGE}`);
1025
1058
  const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths.map((path) => `:(literal)${path}`)]);
1026
1059
  if (commit.code !== 0) {
1027
1060
  await unstage(paths);
1028
- console.error(`gc: git commit failed, the paths were unstaged:
1029
- ${(commit.stderr + commit.stdout).trim()}`);
1061
+ const refusal = `git commit failed, the paths were unstaged:
1062
+ ${(commit.stderr + commit.stdout).trim()}`;
1063
+ if (values.json === true)
1064
+ fail(refusal, 1);
1065
+ console.error(`gc: ${refusal}`);
1030
1066
  return 1;
1031
1067
  }
1032
1068
  const files = await checked(["show", "--format=%h %s", "--name-status", "-M", "HEAD"]);
1033
1069
  const [head = "", ...lines] = files.trimEnd().split(`
1034
1070
  `);
1035
- console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
1071
+ if (values.json === true) {
1072
+ const changes = lines.filter(Boolean).map((line) => {
1073
+ const [letter = "", from = "", to] = line.split("\t");
1074
+ return RENAME.test(letter) ? { status: letter[0] ?? letter, path: to ?? from, from } : { status: letter, path: from };
1075
+ });
1076
+ printJson({ sha: (await checked(["rev-parse", "HEAD"])).trim(), subject: head.slice(head.indexOf(" ") + 1), files: changes });
1077
+ } else {
1078
+ console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
1036
1079
  `));
1080
+ }
1037
1081
  return signals.signal === undefined ? 0 : exitCodeOf(null, signals.signal);
1038
1082
  } finally {
1039
1083
  signals.release();
1040
1084
  }
1041
1085
  }
1042
- process8.exitCode = await runMain({ name: "gc", version, run: main });
1086
+ process9.exitCode = await runMain({ name: "gc", run: main });
package/dist/gst.js CHANGED
@@ -2,14 +2,13 @@
2
2
  // @bun
3
3
 
4
4
  // src/gst.ts
5
- import process8 from "process";
6
-
5
+ import process9 from "process";
7
6
  // ../kit/src/args.ts
8
- import process3 from "process";
7
+ import process4 from "process";
9
8
  import { parseArgs } from "util";
10
9
 
11
10
  // ../kit/src/style.ts
12
- import process from "process";
11
+ import process2 from "process";
13
12
 
14
13
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
15
14
  function x(s) {
@@ -273,10 +272,10 @@ function le(i = {}) {
273
272
  var t = le();
274
273
 
275
274
  // ../kit/src/style.ts
276
- function takesControlCodes(stream, env = process.env) {
275
+ function takesControlCodes(stream, env = process2.env) {
277
276
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
278
277
  }
279
- function paint(stream, env = process.env) {
278
+ function paint(stream, env = process2.env) {
280
279
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
281
280
  }
282
281
  var STATUSES = {
@@ -299,24 +298,30 @@ function printJson(value) {
299
298
  }
300
299
 
301
300
  // ../kit/src/help.ts
302
- import process2 from "process";
301
+ import process3 from "process";
303
302
  var OPTIONAL = /\[[^\]]+\]/g;
304
303
  var USAGE_PREFIX = /^usage:\s*/i;
305
304
  var FULL_STOP = /\.$/;
306
- function usageLine(usage, colors = paint(process2.stdout)) {
305
+ function usageLine(usage, colors = paint(process3.stdout)) {
307
306
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
308
307
  }
309
- function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
310
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
308
+ function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
309
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
311
310
  `);
312
311
  }
313
- function replacesRows(replaces, colors = paint(process2.stdout)) {
312
+ function exitRows(exits, colors = paint(process3.stdout)) {
313
+ if (exits.length === 0)
314
+ return [];
315
+ const width = Math.max(...exits.map(([code]) => String(code).length));
316
+ return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
317
+ }
318
+ function replacesRows(replaces, colors = paint(process3.stdout)) {
314
319
  return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
315
320
  }
316
- function wantsHelpJson(env = process2.env) {
321
+ function wantsHelpJson(env = process3.env) {
317
322
  return env.KIT_HELP === "json";
318
323
  }
319
- function description(usage, { examples = [], replaces } = {}) {
324
+ function description(usage, { examples = [], replaces, exits } = {}, options) {
320
325
  const lines = usage.replace(USAGE_PREFIX, "").split(`
321
326
  `);
322
327
  const first = lines[0];
@@ -327,15 +332,17 @@ function description(usage, { examples = [], replaces } = {}) {
327
332
  synopsis: colon === -1 ? first : first.slice(0, colon),
328
333
  summary: colon === -1 ? fallback : first.slice(colon + 2),
329
334
  ...replaces === undefined ? {} : { replaces },
330
- examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
335
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
336
+ ...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
337
+ ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
331
338
  };
332
339
  }
333
- function exampleRows(examples, colors = paint(process2.stdout)) {
340
+ function exampleRows(examples, colors = paint(process3.stdout)) {
334
341
  if (examples.length === 0)
335
342
  return [];
336
343
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
337
344
  }
338
- function optionRows(options, colors = paint(process2.stdout)) {
345
+ function optionRows(options, colors = paint(process3.stdout)) {
339
346
  const rows = Object.entries(options).map(([name, option]) => {
340
347
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
341
348
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -426,7 +433,7 @@ var OUTPUT_OPTIONS = {
426
433
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
427
434
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
428
435
  };
429
- function applyOutput(color, plain, env = process3.env) {
436
+ function applyOutput(color, plain, env = process4.env) {
430
437
  const when = plain === true ? "never" : color ?? "auto";
431
438
  if (when === "auto")
432
439
  return;
@@ -449,7 +456,7 @@ function parse(args, usage, options, settings = {}) {
449
456
  const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
450
457
  let parsed;
451
458
  try {
452
- parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
459
+ parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
453
460
  } catch (error) {
454
461
  const message = parseError(error);
455
462
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -457,7 +464,7 @@ function parse(args, usage, options, settings = {}) {
457
464
  const values = parsed.values;
458
465
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
459
466
  if (values.help === true) {
460
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
467
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
461
468
  throw new HelpShown;
462
469
  }
463
470
  checkChoices(parsed.values, all);
@@ -499,6 +506,18 @@ function listed(options, allowNegative) {
499
506
  return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
500
507
  }));
501
508
  }
509
+ function withAliases(args, options) {
510
+ const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
511
+ if (named.size === 0)
512
+ return args;
513
+ const separator = args.indexOf("--");
514
+ const own = separator === -1 ? args : args.slice(0, separator);
515
+ return [...own.map((arg) => {
516
+ const at = arg.indexOf("=");
517
+ const current = named.get(at === -1 ? arg : arg.slice(0, at));
518
+ return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
519
+ }), ...separator === -1 ? [] : args.slice(separator)];
520
+ }
502
521
  function withBare(args, options) {
503
522
  const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
504
523
  if (bare.size === 0)
@@ -585,7 +604,7 @@ function nearestOption(message, options, allowNegative) {
585
604
  }
586
605
  // ../kit/src/process.ts
587
606
  import { constants } from "os";
588
- import process4 from "process";
607
+ import process5 from "process";
589
608
  var KILL_GRACE_MS = 2000;
590
609
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
591
610
  function exitCodeOf(code, signal) {
@@ -607,7 +626,7 @@ function holdSignals(cleanup) {
607
626
  },
608
627
  release: () => {
609
628
  for (const signal of SIGNALS)
610
- process4.off(signal, onSignal);
629
+ process5.off(signal, onSignal);
611
630
  }
612
631
  };
613
632
  function onSignal(signal) {
@@ -620,10 +639,10 @@ function holdSignals(cleanup) {
620
639
  return;
621
640
  held.release();
622
641
  cleanup(signal);
623
- process4.kill(process4.pid, signal);
642
+ process5.kill(process5.pid, signal);
624
643
  }
625
644
  for (const signal of SIGNALS)
626
- process4.on(signal, onSignal);
645
+ process5.on(signal, onSignal);
627
646
  return held;
628
647
  }
629
648
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -637,7 +656,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
637
656
  return;
638
657
  try {
639
658
  if (grouped)
640
- process4.kill(-proc.pid, killing);
659
+ process5.kill(-proc.pid, killing);
641
660
  else
642
661
  proc.kill(killing);
643
662
  } catch {}
@@ -711,13 +730,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
711
730
  var RESET_STYLE = `${ESC}[0m`;
712
731
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
713
732
  // ../kit/src/cli.ts
714
- import process6 from "process";
733
+ import { readFileSync, realpathSync } from "fs";
734
+ import { dirname as dirname2, join as join2 } from "path";
735
+ import process7 from "process";
715
736
 
716
737
  // ../kit/src/usage.ts
717
738
  import { appendFileSync, mkdirSync } from "fs";
718
739
  import { homedir } from "os";
719
740
  import { dirname, isAbsolute, join } from "path";
720
- import process5 from "process";
741
+ import process6 from "process";
721
742
 
722
743
  // ../kit/src/logs.ts
723
744
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -731,14 +752,14 @@ var usageError;
731
752
  function noteUsageError(message) {
732
753
  usageError = message;
733
754
  }
734
- function stateHome(env = process5.env) {
755
+ function stateHome(env = process6.env) {
735
756
  const dir = env.XDG_STATE_HOME;
736
757
  return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
737
758
  }
738
- function usagePath(env = process5.env) {
759
+ function usagePath(env = process6.env) {
739
760
  return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
740
761
  }
741
- function usageRecorded(env = process5.env) {
762
+ function usageRecorded(env = process6.env) {
742
763
  const off = env.KAYNOOO_CLI_NO_USAGE;
743
764
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
744
765
  }
@@ -752,7 +773,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
752
773
  usageError = undefined;
753
774
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
754
775
  }
755
- function recordUsage(entry, env = process5.env) {
776
+ function recordUsage(entry, env = process6.env) {
756
777
  if (!usageRecorded(env))
757
778
  return;
758
779
  try {
@@ -770,8 +791,8 @@ var LEVEL_OPTIONS = {
770
791
  };
771
792
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
772
793
  function printError(prefix, message, hint, cause) {
773
- const colors = paint(process6.stderr);
774
- const styled = takesControlCodes(process6.stderr);
794
+ const colors = paint(process7.stderr);
795
+ const styled = takesControlCodes(process7.stderr);
775
796
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
776
797
  const under = (label, text, tint) => text === undefined ? "" : `
777
798
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -856,11 +877,22 @@ async function printCandidates(found) {
856
877
  console.log(line);
857
878
  return 0;
858
879
  }
859
- async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
880
+ function packageVersion(entry = Bun.main) {
881
+ for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
882
+ try {
883
+ const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
884
+ if (typeof version === "string")
885
+ return version;
886
+ } catch {}
887
+ if (dirname2(dir) === dir)
888
+ return "0.0.0";
889
+ }
890
+ }
891
+ async function runMain({ name, version, run, redact, usage }, argv = process7.argv.slice(2)) {
860
892
  if (argv[0] === COMPLETE)
861
893
  return printCandidates(leafCandidates(run, argv.slice(1)));
862
894
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
863
- console.log(version);
895
+ console.log(version ?? packageVersion());
864
896
  return 0;
865
897
  }
866
898
  let code;
@@ -869,8 +901,11 @@ async function runMain({ name, version, run, redact, usage }, argv = process6.ar
869
901
  } catch (error) {
870
902
  code = reportThrown(name, error, redact, wantsJson(argv));
871
903
  }
872
- if (usage !== false)
873
- recordUsage(usageEntry(name, undefined, argv, code));
904
+ if (usage !== false) {
905
+ try {
906
+ recordUsage(usageEntry(name, undefined, argv, code));
907
+ } catch {}
908
+ }
874
909
  return code;
875
910
  }
876
911
  // ../kit/src/secrets.ts
@@ -879,9 +914,6 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
879
914
  var {Glob } = globalThis.Bun;
880
915
  var SESSION_FILES = new Glob("*.json");
881
916
  var ACCOUNT_DIRS = new Glob("*/sessions");
882
- // package.json
883
- var version = "0.5.2";
884
-
885
917
  // src/git.ts
886
918
  async function git2(args, env) {
887
919
  const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
@@ -899,14 +931,14 @@ function unquote(path) {
899
931
  if (!path.startsWith('"') || !path.endsWith('"'))
900
932
  return path;
901
933
  const bytes = [];
902
- const text = path.slice(1, -1);
934
+ const text = [...path.slice(1, -1)];
903
935
  for (let i = 0;i < text.length; i++) {
904
936
  const char = text[i] ?? "";
905
937
  const next = text[i + 1] ?? "";
906
938
  if (char !== "\\") {
907
939
  bytes.push(...ENCODER.encode(char));
908
940
  } else if (OCTAL.test(next)) {
909
- bytes.push(Number.parseInt(text.slice(i + 1, i + 4), 8));
941
+ bytes.push(Number.parseInt(text.slice(i + 1, i + 4).join(""), 8));
910
942
  i += 3;
911
943
  } else {
912
944
  bytes.push(ESCAPES[next] ?? next.charCodeAt(0));
@@ -1021,4 +1053,4 @@ ${USAGE}`);
1021
1053
  `));
1022
1054
  return 0;
1023
1055
  }
1024
- process8.exitCode = await runMain({ name: "gst", version, run: main });
1056
+ process9.exitCode = await runMain({ name: "gst", run: main });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.5.2",
5
- "description": "gst and gc: a repository's state in one call, and a commit of exactly the paths given, its message checked before anything is staged.",
4
+ "version": "0.7.0",
5
+ "description": "gst, gc and gb: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, and a branch picked with fzf.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
8
  "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/git#readme",
@@ -24,7 +24,8 @@
24
24
  },
25
25
  "bin": {
26
26
  "gst": "./dist/gst.js",
27
- "gc": "./dist/gc.js"
27
+ "gc": "./dist/gc.js",
28
+ "gb": "./dist/gb.js"
28
29
  },
29
30
  "files": [
30
31
  "dist",
@@ -37,9 +38,10 @@
37
38
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
38
39
  },
39
40
  "scripts": {
40
- "build": "$npm_execpath build src/gst.ts src/gc.ts --target bun --outdir dist",
41
+ "build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts --target bun --outdir dist",
41
42
  "gst": "$npm_execpath src/gst.ts",
42
- "gc": "$npm_execpath src/gc.ts"
43
+ "gc": "$npm_execpath src/gc.ts",
44
+ "gb": "$npm_execpath src/gb.ts"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@kaynooo/cli-kit": "0.20.0"