@kaynooo/cli-git 0.6.0 → 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/README.md CHANGED
@@ -10,17 +10,17 @@ gc 'fix(band): keep it visible' -m 'The band stays above a long prompt.' --ticke
10
10
 
11
11
  ## gst
12
12
 
13
- Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `--log N` adds the last N commits as `<sha7> <title>`. `--json` prints the same as `{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}`, a change as `{status, path, from?}`. It takes no index lock, so it runs beside another git command. Exit codes: 0, 1 outside a repository, 2 a usage error.
13
+ Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `--log N` adds the last N commits as `<sha7> <title>`. `--json` prints the same as `{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}`, a change as `{status, path, from?}`. It takes no index lock, so it runs beside another git command. Exit codes: 0, 2 outside a repository or a usage error.
14
14
 
15
15
  ## gc
16
16
 
17
- `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter.
17
+ `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter; `--json` prints `{sha, subject, files: [{status, path, from?}]}`.
18
18
 
19
19
  - The message is the title, then the `-m` lines, then the `--ticket` lines, each block after a blank line; ticket lines are copied verbatim and read `#<n> - <title>`.
20
20
  - Before anything is staged it refuses, exit 1, saying which rule broke: a title that is no Conventional Commit, a title over one line, more than two description lines, a bullet list, a hard-wrapped sentence, any trailer (`Co-Authored-By`, `Signed-off-by`, "Generated with"). A breaking change (`feat!:` or a `BREAKING CHANGE:` line) may give full details.
21
21
  - It also refuses, with nothing staged, a path with no change (unchanged, ignored or missing) and an index already holding files beyond the given paths, which the commit would carry along.
22
22
  - A path may be a directory or a deleted file. When git refuses the commit (a hook), the paths are unstaged again and git's output is shown.
23
- - Exit codes: 0 committed, 1 refused, 2 a usage error.
23
+ - Exit codes: 0 committed, 1 refused, 2 a usage error or outside a git repository.
24
24
 
25
25
  ## gb
26
26
 
package/dist/gb.js CHANGED
@@ -2,14 +2,13 @@
2
2
  // @bun
3
3
 
4
4
  // src/gb.ts
5
- import process9 from "process";
6
-
5
+ import process10 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,12 +914,9 @@ 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.6.0";
884
-
885
917
  // src/branch.ts
886
918
  import { basename } from "path";
887
- import process8 from "process";
919
+ import process9 from "process";
888
920
 
889
921
  // ../kit/src/fzf.ts
890
922
  function table(rows) {
@@ -958,9 +990,8 @@ gb -d <branch>
958
990
 
959
991
  Without a branch, picks one with fzf when it is installed and a terminal is attached: the branches last checked out first, as the reflog has them, then the other local ones, then the remote ones with no local branch yet. The header says where HEAD stands, each row how its branch stands against its upstream and whether it is merged into the base. enter switches to it (a remote one gets its local tracking branch), ctrl-n creates a branch named after the query, ctrl-d deletes the highlighted local branch with \`git branch -d\`, which refuses one not merged yet, and ctrl-r fetches, prunes and lists again. Without fzf or a terminal it lists the branches instead.
960
992
  \`gb <branch>\` switches without the picker, a bare name finding the remote branch it would create. \`gb -\` goes back to the previous branch, \`gb -c <name>\` creates one and switches to it, \`gb -d <branch>\` deletes a local one.
961
- A branch checked out in another worktree cannot be switched to: gb prints that worktree's path on stdout and a hint on stderr, since a command cannot change its parent shell's folder.
962
-
963
- Exits with the code of the git command it ran, 1 when there is no branch by that name or nothing was picked, 2 outside a git repository.`;
993
+ A branch checked out in another worktree cannot be switched to: gb prints that worktree's path on stdout and a hint on stderr, since a command cannot change its parent shell's folder.`;
994
+ var EXITS = [[0, "it switched, created, deleted or listed"], ["git", "the code of the git command it ran, when that failed"], [1, "there is no branch by that name or nothing was picked"], [2, "outside a git repository or a usage error"]];
964
995
  var options = {
965
996
  create: { type: "boolean", short: "c", description: "create the branch named by the rest of the line and switch to it" },
966
997
  delete: { type: "boolean", short: "d", description: "delete the local branch with git branch -d" },
@@ -1086,6 +1117,9 @@ function load() {
1086
1117
  return { found, current, all: ordered(found, visited(read(["reflog", "-n", "2000", "--format=%gs"]).split(`
1087
1118
  `)), current) };
1088
1119
  }
1120
+ function isCurrent(named, current, found) {
1121
+ return current !== "" && (named === current || found.some((branch) => branch.remote && branch.name === named && localName(branch.name) === current));
1122
+ }
1089
1123
  function header(found, current, failure = "") {
1090
1124
  const changed = read(["status", "--porcelain", "--untracked-files=no"]).split(`
1091
1125
  `).filter(Boolean).length;
@@ -1148,7 +1182,7 @@ async function gb(args) {
1148
1182
  if (["--show", "--fetch", "--list", "--rows", "--names"].includes(flag))
1149
1183
  return hidden(flag, args.slice(1)) ?? 0;
1150
1184
  const emitting = flag === "--emit";
1151
- const parsed = parse(emitting ? args.slice(1) : args, usage2, options, { replaces: "git switch, git branch -d and git checkout typed per branch", examples: ["gb", ["gb feature", "switch to feature, or create it from origin/feature"], ["gb -", "back to the previous branch"], ["gb -c fix/login", "create a branch and switch to it"], ["gb -d old", "delete a merged local branch"]] });
1185
+ const parsed = parse(emitting ? args.slice(1) : args, usage2, options, { exits: EXITS, replaces: "git switch, git branch -d and git checkout typed per branch", examples: ["gb", ["gb feature", "switch to feature, or create it from origin/feature"], ["gb -", "back to the previous branch"], ["gb -c fix/login", "create a branch and switch to it"], ["gb -d old", "delete a merged local branch"]] });
1152
1186
  const [named] = parsed.positionals;
1153
1187
  if (read(["rev-parse", "--git-dir"]) === "")
1154
1188
  fail("not a git repository", 2);
@@ -1158,7 +1192,7 @@ async function gb(args) {
1158
1192
  const name = parsed.positionals.join(" ");
1159
1193
  command = create(name);
1160
1194
  typed = `-c ${name}`;
1161
- } else if (named === "-") {
1195
+ } else if (named === "-" && parsed.values.delete !== true) {
1162
1196
  command = ["git", "switch", "-"];
1163
1197
  typed = "-";
1164
1198
  } else {
@@ -1167,7 +1201,7 @@ async function gb(args) {
1167
1201
  let branch;
1168
1202
  let key = "";
1169
1203
  if (named === undefined) {
1170
- const interactive = process8.stdin.isTTY && process8.stderr.isTTY && parsed.values.json !== true;
1204
+ const interactive = process9.stdin.isTTY && process9.stderr.isTTY && parsed.values.json !== true;
1171
1205
  if (!interactive || Bun.which("fzf") === null) {
1172
1206
  if (emitting)
1173
1207
  fail("the picker needs a terminal and fzf", 1);
@@ -1176,11 +1210,11 @@ async function gb(args) {
1176
1210
  if (parsed.values.json === true)
1177
1211
  printJson(all);
1178
1212
  else
1179
- console.log(table(all.map(row)).map((line) => process8.stdout.isTTY ? line : Bun.stripANSI(line)).join(`
1213
+ console.log(table(all.map(row)).map((line) => process9.stdout.isTTY ? line : Bun.stripANSI(line)).join(`
1180
1214
  `));
1181
1215
  return 0;
1182
1216
  }
1183
- const self = `${process8.execPath} ${process8.argv[1]}`;
1217
+ const self = `${process9.execPath} ${process9.argv[1]}`;
1184
1218
  const picked = fzf(all.map(row), {
1185
1219
  prompt: "gb> ",
1186
1220
  header: header(found, current),
@@ -1199,6 +1233,11 @@ async function gb(args) {
1199
1233
  if (!branch)
1200
1234
  return 1;
1201
1235
  key = picked.key;
1236
+ } else if (deleting && named === "-") {
1237
+ return fail("-d takes a branch name, not -", 1);
1238
+ } else if (!deleting && isCurrent(named, current, found)) {
1239
+ console.error(`already on ${current}`);
1240
+ return 0;
1202
1241
  } else {
1203
1242
  branch = all.find((candidate) => candidate.name === named) ?? all.find((candidate) => candidate.remote && localName(candidate.name) === named);
1204
1243
  if (!branch) {
@@ -1231,4 +1270,4 @@ async function finish(command, typed, emitting) {
1231
1270
  }
1232
1271
 
1233
1272
  // src/gb.ts
1234
- process9.exitCode = await runMain({ name: "gb", version, run: gb });
1273
+ process10.exitCode = await runMain({ name: "gb", run: gb });
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.6.0";
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.6.0";
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
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",