@kaynooo/cli-forgejo 0.10.0 → 0.12.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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/dist/cli.js +196 -42
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -20,12 +20,12 @@ Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea
20
20
  | `ft board` | open issues: available, taken by a live session, or claimed with no live session here, each claim with its boxes left and a stale one with its latest note (`-q <regex>` on titles, `--state available\|taken\|away`, `-L`, `-m <milestone>`, `--json`) |
21
21
  | `ft digest` | one screen for a session starting cold: the issues this session holds with their boxes left, claims no live session answers to, red or running CI on the default branch, unpushed commits, dirty files and TODO comments naming a closed issue (needs `todo-scan` on the PATH; empty sections left out, `--json`) |
22
22
  | `ft take <n>...` / `ft drop <n>...` | claims or gives back issues for the calling Claude Code session, `--lane` as `lane-<s>-<n>` |
23
- | `ft issue <n>...` | an issue's state, claim and description, its checklist boxes numbered in place (`-c` comments, `-t` only the boxes left, `-b` only the raw description to edit, `--json`) |
23
+ | `ft issue [<n>...]` | an issue's state, claim and description, its checklist boxes numbered in place, the issues this session holds when no number is given (`-c` comments, `-t` only the boxes left, `-b` only the raw description to edit, `--json`) |
24
24
  | `ft new -t <title>` | creates an issue and prints its number and url; `-F <file>` (`-F -` for stdin) is the description, `-L a,b` the labels and `-m <milestone>` the milestone, refused before anything is created when the repository lacks one |
25
25
  | `ft edit <n>` | replaces the title (`-t`) and/or the description (`-F <file>`, `-F -` for stdin); `--append` adds the `-F` text after the description instead, `--add-box <text>` (repeatable) an unticked box after the last one, `-m <milestone>` moves it to a milestone and `-m ''` takes it out |
26
- | `ft tick <n> <box>...` | ticks boxes by number or text, `--undo` unticks, `-m <text>` or `-F <file>` comments too; `--closed` ticks instead every `- [ ] #<n>` line of a release plan whose issue is closed |
27
- | `ft comment <n> [text]` | comments on an issue, from `-F <file>` or stdin when no text is given, so a heredoc needs no escaping |
28
- | `ft fixed <n> [sha]...` | comments `Fixed in <a>, <b> and <c>: <subject>` and closes; with no sha it takes the commits on origin's default branch naming `#<n>` and says which; refuses while boxes are left unless `--tick` ticks them first; then ticks its `- [ ] #<n>` line in every open issue listing it, and names those |
26
+ | `ft tick [<n>] <box>...` | ticks boxes by number or text, `--undo` unticks, `-m <text>` or `-F <file>` comments too; `--closed` ticks instead every `- [ ] #<n>` line of a release plan whose issue is closed |
27
+ | `ft comment [<n>] [text]` | comments on an issue, from `-F <file>` or stdin when no text is given, so a heredoc needs no escaping |
28
+ | `ft fixed [<n>] [sha]...` | comments `Fixed in <a>, <b> and <c>: <subject>` and closes; with no sha it takes the commits on origin's default branch naming `#<n>` and says which; refuses while boxes are left unless `--tick` ticks them first; then ticks its `- [ ] #<n>` line in every open issue listing it, and names those |
29
29
  | `ft close <n>... [-m reason]` | closes issues no commit fixed (a duplicate, one dropped), posting the reason first; `ft reopen` reopens them the same way |
30
30
  | `ft label <n> [+]a -b` | adds the labels named bare or with `+`, removes those named with `-`, refusing one the repository lacks, and prints the issue's labels |
31
31
  | `ft plan add <plan> <n>...` / `ft plan carry <from> <to>` | adds `- [ ] #<n> <title>` lines to a release plan's checklist, or copies one plan's unticked `#<n>` lines into the next, both under `--section "Bugs:"` (created when missing) and skipping issues already listed |
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import process3 from "process";
14
14
  // ../kit/src/style.ts
15
15
  import process2 from "process";
16
16
 
17
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
18
  function x(s) {
19
19
  let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
20
20
  if (!/^[a-f0-9]+$/.test(r))
@@ -234,7 +234,7 @@ class e {
234
234
  }
235
235
  }
236
236
 
237
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
237
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
238
  var r = 39;
239
239
  var o = 49;
240
240
  var f2 = "\x1B[";
@@ -453,8 +453,12 @@ class HelpShown extends Exit {
453
453
 
454
454
  class Completing {
455
455
  options;
456
- constructor(options) {
456
+ positionals;
457
+ candidates;
458
+ constructor(options, positionals = [], candidates = {}) {
457
459
  this.options = options;
460
+ this.positionals = positionals;
461
+ this.candidates = candidates;
458
462
  }
459
463
  }
460
464
  var completion = { active: false };
@@ -497,8 +501,10 @@ function exampleRows(examples, colors = paint(process4.stdout)) {
497
501
  function optionRows(options, colors = paint(process4.stdout)) {
498
502
  const rows = Object.entries(options).map(([name, option]) => {
499
503
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
500
- const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
501
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
504
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
505
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
506
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
507
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
502
508
  });
503
509
  const width = Math.max(0, ...rows.map((row) => row.width));
504
510
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
@@ -524,14 +530,13 @@ function applyOutput(color, plain, env = process4.env) {
524
530
  function parse(args, usage, options, settings = {}) {
525
531
  const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
526
532
  const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
533
+ const listing = listed(all, settings.allowNegative === true);
527
534
  if (completion.active)
528
- throw new Completing(all);
529
- const separator = settings.rest === true ? args.indexOf("--") : -1;
530
- const own = separator === -1 ? args : args.slice(0, separator);
531
- const rest = separator === -1 ? undefined : args.slice(separator + 1);
535
+ throw new Completing(listing, settings.positionals, settings.candidates);
536
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
532
537
  let parsed;
533
538
  try {
534
- parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
539
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
535
540
  } catch (error) {
536
541
  const message = parseError(error);
537
542
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -539,12 +544,84 @@ function parse(args, usage, options, settings = {}) {
539
544
  const values = parsed.values;
540
545
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
541
546
  if (values.help === true) {
542
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
547
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
543
548
  throw new HelpShown;
544
549
  }
550
+ checkChoices(parsed.values, all);
551
+ checkConflicts(parsed.values, all);
545
552
  if (settings.positionals !== undefined)
546
553
  checkPositionals(parsed.positionals, settings.positionals);
547
- return { ...parsed, positionals: parsed.positionals, rest };
554
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
555
+ }
556
+ function splitRest(args, passes) {
557
+ const separator = passes ? args.indexOf("--") : -1;
558
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
559
+ }
560
+ function splitTrailing(args, options, count) {
561
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
562
+ let seen = 0;
563
+ if (count === 0)
564
+ return { own: args, rest: undefined };
565
+ for (let at = 0;at < args.length; at++) {
566
+ const word = args[at];
567
+ if (word === "--")
568
+ break;
569
+ if (word.startsWith("-")) {
570
+ if (takesValue(word))
571
+ at++;
572
+ continue;
573
+ }
574
+ seen++;
575
+ if (seen === count)
576
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
577
+ }
578
+ return { own: args, rest: undefined };
579
+ }
580
+ function listed(options, allowNegative) {
581
+ if (!allowNegative)
582
+ return options;
583
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
584
+ if (option.type !== "boolean" || option.negative === undefined)
585
+ return [[name, option]];
586
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
587
+ }));
588
+ }
589
+ function withBare(args, options) {
590
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
591
+ if (bare.size === 0)
592
+ return args;
593
+ const separator = args.indexOf("--");
594
+ const own = separator === -1 ? args : args.slice(0, separator);
595
+ return [...own.flatMap((arg, index) => {
596
+ const optional = bare.get(arg);
597
+ const next = own[index + 1];
598
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
599
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
600
+ }), ...separator === -1 ? [] : args.slice(separator)];
601
+ }
602
+ function checkConflicts(values, options) {
603
+ const given = (name) => values[name] !== undefined && values[name] !== false;
604
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
605
+ const other = given(name) ? conflicts.find(given) : undefined;
606
+ if (other !== undefined)
607
+ badUsage(`--${name} cannot be used with --${other}`);
608
+ }
609
+ }
610
+ function checkChoices(values, options) {
611
+ for (const [name, option] of Object.entries(options)) {
612
+ if (option.choices === undefined)
613
+ continue;
614
+ const given = values[name];
615
+ for (const value of Array.isArray(given) ? given : [given]) {
616
+ if (typeof value === "string")
617
+ oneOf(value, name, option.choices);
618
+ }
619
+ }
620
+ }
621
+ function oneOf(value, name, choices) {
622
+ if (!choices.includes(value))
623
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
624
+ return value;
548
625
  }
549
626
  function checkPositionals(given, names) {
550
627
  const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
@@ -1002,8 +1079,9 @@ var LEVEL_OPTIONS = {
1002
1079
  help: { type: "boolean", short: "h", description: "show this help" }
1003
1080
  };
1004
1081
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1005
- async function commandRows(commands, colors) {
1006
- const width = Math.max(...Object.keys(commands).map((name) => name.length));
1082
+ async function commandRows(all, colors) {
1083
+ const commands = shown(all);
1084
+ const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
1007
1085
  const groups = new Map([["Commands:", []]]);
1008
1086
  const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
1009
1087
  for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
@@ -1014,6 +1092,9 @@ async function commandRows(commands, colors) {
1014
1092
  }
1015
1093
  return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
1016
1094
  }
1095
+ function shown(commands) {
1096
+ return Object.fromEntries(Object.entries(commands).filter(([, { hidden }]) => hidden !== true));
1097
+ }
1017
1098
  function takeOutputFlags(argv) {
1018
1099
  let index = 0;
1019
1100
  for (;index < argv.length; index++) {
@@ -1112,6 +1193,14 @@ async function dispatch(level, typed, { version, redact }) {
1112
1193
  return reportThrown(prefix, error);
1113
1194
  }
1114
1195
  const [name, ...args] = argv;
1196
+ const fallback = level.defaultCommand === undefined ? undefined : level.commands[level.defaultCommand];
1197
+ if (name === undefined && level.runBare && fallback !== undefined && "run" in fallback) {
1198
+ try {
1199
+ return await fallback.run([]);
1200
+ } catch (error) {
1201
+ return reportThrown(`${prefix} ${level.defaultCommand}`, error, redact, false);
1202
+ }
1203
+ }
1115
1204
  if (name === undefined && level.path.length > 1) {
1116
1205
  console.error(await help(await expand(level, [...level.path.slice(1), ...argv]), process8.stderr));
1117
1206
  return 2;
@@ -1126,6 +1215,7 @@ async function dispatch(level, typed, { version, redact }) {
1126
1215
  }
1127
1216
  let command = level.commands[level.aliases?.[name] ?? name];
1128
1217
  let rest = args;
1218
+ let ran = name;
1129
1219
  if (command === undefined && level.lazy.length > 0) {
1130
1220
  level = await expand(level, [...level.path.slice(1), ...argv]);
1131
1221
  command = level.commands[level.aliases?.[name] ?? name];
@@ -1133,40 +1223,77 @@ async function dispatch(level, typed, { version, redact }) {
1133
1223
  if (command === undefined && level.defaultCommand !== undefined) {
1134
1224
  command = level.commands[level.defaultCommand];
1135
1225
  rest = argv;
1226
+ ran = level.defaultCommand;
1136
1227
  }
1137
1228
  if (command === undefined) {
1138
- const meant = closest(name, Object.keys(level.commands));
1229
+ const meant = closest(name, Object.keys(shown(level.commands)));
1139
1230
  printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
1140
1231
  return 2;
1141
1232
  }
1142
1233
  if ("commands" in command) {
1143
1234
  const { summary } = command;
1144
- return dispatch({ path: [...level.path, name], header: (colors, text) => `${colors.bold(`${prefix} ${name}`)} ${text}`, summary, ...scopeOf(command.commands, command.extraCommands, command.aliases), defaultCommand: undefined, examples: command.examples, replaces: undefined }, rest, { version, redact });
1235
+ return dispatch({ path: [...level.path, name], header: (colors, text) => `${colors.bold(`${prefix} ${name}`)} ${text}`, summary, ...scopeOf(command.commands, command.extraCommands, command.aliases), defaultCommand: undefined, runBare: false, examples: command.examples, replaces: undefined }, rest, { version, redact });
1145
1236
  }
1146
1237
  try {
1147
1238
  return await command.run(rest);
1148
1239
  } catch (error) {
1149
- return reportThrown(`${prefix} ${name}`, error, redact, wantsJson(rest));
1240
+ return reportThrown(`${prefix} ${ran}`, error, redact, wantsJson(rest));
1150
1241
  }
1151
1242
  }
1152
1243
  var COMPLETE = "__complete";
1153
1244
  var FILES = "__files__";
1154
- async function optionsOf(run) {
1245
+ async function completingOf(run) {
1155
1246
  completion.active = true;
1156
1247
  try {
1157
1248
  await run([]);
1158
1249
  } catch (error) {
1159
1250
  if (error instanceof Completing)
1160
- return error.options;
1251
+ return error;
1161
1252
  } finally {
1162
1253
  completion.active = false;
1163
1254
  }
1164
- return {};
1255
+ return new Completing({});
1256
+ }
1257
+ async function optionsOf(run) {
1258
+ return (await completingOf(run)).options;
1259
+ }
1260
+ function candidateLine(candidate) {
1261
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
1262
+ }
1263
+ function positionalBeingTyped(before, { options, positionals }) {
1264
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1265
+ let index = 0;
1266
+ let at = 0;
1267
+ while (at < before.length) {
1268
+ const word = before[at];
1269
+ if (word === "--") {
1270
+ index += before.length - at - 1;
1271
+ break;
1272
+ }
1273
+ if (!word.startsWith("-"))
1274
+ index++;
1275
+ else if (takesValue(word))
1276
+ at++;
1277
+ at++;
1278
+ }
1279
+ const last = positionals.at(-1);
1280
+ if (index < positionals.length)
1281
+ return positionals[index];
1282
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1165
1283
  }
1166
1284
  async function leafCandidates(run, words) {
1167
- if (!(words.at(-1) ?? "").startsWith("-"))
1168
- return [FILES];
1169
- return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1285
+ const completing = await completingOf(run);
1286
+ if ((words.at(-1) ?? "").startsWith("-"))
1287
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1288
+ const flag = words.at(-2);
1289
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1290
+ if (option?.type === "string") {
1291
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1292
+ return values === undefined ? [FILES] : values.map(candidateLine);
1293
+ }
1294
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
1295
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
1296
+ return values === undefined ? [FILES] : values.map(candidateLine);
1170
1297
  }
1171
1298
  async function candidates(scope, defaultCommand, words, before = []) {
1172
1299
  const [word = "", ...rest] = words;
@@ -1177,8 +1304,13 @@ async function candidates(scope, defaultCommand, words, before = []) {
1177
1304
  ({ commands, aliases } = await expand(scope, [...before, ...words]));
1178
1305
  command = commands[aliases?.[word] ?? word];
1179
1306
  }
1180
- if (listing)
1181
- return Promise.all(Object.entries(commands).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
1307
+ if (listing) {
1308
+ const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
1309
+ const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
1310
+ const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
1311
+ const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
1312
+ return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
1313
+ }
1182
1314
  if (command === undefined) {
1183
1315
  const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
1184
1316
  return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
@@ -1193,7 +1325,7 @@ async function printCandidates(found) {
1193
1325
  async function runCli(cli, argv = process8.argv.slice(2)) {
1194
1326
  if (argv[0] === COMPLETE)
1195
1327
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1196
- return dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(cli.version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, examples: cli.examples, replaces: cli.replaces }, argv, { version: cli.version, redact: cli.redact });
1328
+ return dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(cli.version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version: cli.version, redact: cli.redact });
1197
1329
  }
1198
1330
  // ../kit/src/git.ts
1199
1331
  import { basename, dirname } from "path";
@@ -1232,7 +1364,7 @@ async function leaveWorktree() {
1232
1364
  // ../kit/src/limit.ts
1233
1365
  function limitOptions(fallback) {
1234
1366
  return {
1235
- limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
1367
+ limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
1236
1368
  full: { type: "boolean", description: "show every row" }
1237
1369
  };
1238
1370
  }
@@ -1324,7 +1456,7 @@ async function currentSession(sessions) {
1324
1456
  return;
1325
1457
  }
1326
1458
  // package.json
1327
- var version = "0.10.0";
1459
+ var version = "0.12.0";
1328
1460
 
1329
1461
  // src/args.ts
1330
1462
  var repoOption = {
@@ -1781,6 +1913,14 @@ async function boardRows(issues, sessions, repo) {
1781
1913
  return { issue, standing: standing(latestClaim(own, author), sessions), comments: own };
1782
1914
  });
1783
1915
  }
1916
+ function heldBy(rows, session) {
1917
+ return rows.flatMap(({ issue, standing: now }) => now.state === "taken" && now.session.pid === session.pid ? [issue.number] : []);
1918
+ }
1919
+ async function heldIssues(repo) {
1920
+ const sessions = await liveSessions();
1921
+ const session = await currentSession(sessions);
1922
+ return session === undefined ? [] : heldBy(await boardRows(await openIssues(undefined, repo), sessions, repo), session);
1923
+ }
1784
1924
  function boardJson(rows) {
1785
1925
  return rows.map(({ issue, standing: { state, ...rest }, comments: own }) => {
1786
1926
  const list = boxes(issue.body);
@@ -2443,10 +2583,11 @@ ${labelUsage}`);
2443
2583
  }
2444
2584
 
2445
2585
  // src/commands/issue.ts
2446
- var issueUsage = `ft issue <n>...
2586
+ var issueUsage = `ft issue [<n>...]
2447
2587
 
2448
2588
  Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it.
2449
2589
  With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
2590
+ With no number, prints the open issues this session holds (\`ft take\`), and exits 2 when it holds none.
2450
2591
 
2451
2592
  Exits 0 when it printed them, 1 when an issue cannot be read, 2 on a usage error.`;
2452
2593
  var issueOptions = {
@@ -2501,7 +2642,8 @@ function issueJson(found, comments, author) {
2501
2642
  async function issue(args) {
2502
2643
  const parsed = parse(args, issueUsage, issueOptions);
2503
2644
  const { values, positionals } = parsed;
2504
- const numbers = issueNumbers(positionals, issueUsage);
2645
+ const held = positionals.length === 0 ? await heldIssues(values.repo) : [];
2646
+ const numbers = held.length === 0 ? issueNumbers(positionals, issueUsage) : held;
2505
2647
  if (values.body === true) {
2506
2648
  const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
2507
2649
  `, `
@@ -2527,6 +2669,17 @@ async function issue(args) {
2527
2669
  `));
2528
2670
  return 0;
2529
2671
  }
2672
+ var ISSUE_REFERENCE = /^#?\d+$/;
2673
+ async function targetIssue(positionals, repo, usage) {
2674
+ if (positionals[0] !== undefined && ISSUE_REFERENCE.test(positionals[0]))
2675
+ return { number: issueNumber(positionals[0], usage), rest: positionals.slice(1) };
2676
+ const [only, ...others] = await heldIssues(repo);
2677
+ if (only === undefined || others.length > 0)
2678
+ fail(`${only === undefined ? "an issue number is needed, this session holds none" : "an issue number is needed, this session holds several"}
2679
+
2680
+ ${usage}`);
2681
+ return { number: only, rest: positionals };
2682
+ }
2530
2683
  var noteOptions = {
2531
2684
  message: { type: "string", short: "m", description: "comment this text on the issue" },
2532
2685
  file: { type: "string", short: "F", description: "comment the text of this file, - for stdin" }
@@ -2635,11 +2788,13 @@ ${text}` : body;
2635
2788
  console.log(`edited #${number}`);
2636
2789
  return 0;
2637
2790
  }
2638
- var tickUsage = `ft tick <n> <box>...
2791
+ var tickUsage = `ft tick [<n>] <box>...
2639
2792
 
2640
2793
  Ticks checklist boxes of issue <n>, each given by its number from \`ft issue\` or by text matching exactly one box, then posts the -m or -F comment.
2641
2794
  With --closed, ticks instead every box opening with \`#<issue>\` whose issue is closed, as a release plan lists them.
2642
2795
 
2796
+ Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several.
2797
+
2643
2798
  Exits 0 when it ticked the boxes, 1 when Forgejo refuses, 2 on a usage error or a box matching none or several.`;
2644
2799
  var tickOptions = {
2645
2800
  undo: { type: "boolean", short: "u", description: "untick them instead" },
@@ -2657,8 +2812,7 @@ function tickedOrFail(number, run) {
2657
2812
  async function tick(args) {
2658
2813
  const parsed = parse(args, tickUsage, tickOptions);
2659
2814
  const { values, positionals } = parsed;
2660
- const number = issueNumber(positionals[0], tickUsage);
2661
- const picks = positionals.slice(1);
2815
+ const { number, rest: picks } = await targetIssue(positionals, values.repo, tickUsage);
2662
2816
  if (values.closed === true && (picks.length > 0 || values.undo === true))
2663
2817
  fail(`--closed takes no boxes and no --undo
2664
2818
 
@@ -2689,9 +2843,10 @@ ${tickUsage}`);
2689
2843
  }
2690
2844
  return 0;
2691
2845
  }
2692
- var commentUsage = `ft comment <n> [text]
2846
+ var commentUsage = `ft comment [<n>] [text]
2693
2847
 
2694
2848
  Posts a comment on issue <n>: the text given, -F <file>, or stdin when neither is, so a heredoc needs no escaping.
2849
+ Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several.
2695
2850
 
2696
2851
  Exits 0 when it posted the comment, 1 when Forgejo refuses, 2 on a usage error.`;
2697
2852
  var commentOptions = {
@@ -2701,8 +2856,8 @@ var commentOptions = {
2701
2856
  async function commentOn(args) {
2702
2857
  const parsed = parse(args, commentUsage, commentOptions);
2703
2858
  const { values, positionals } = parsed;
2704
- const number = issueNumber(positionals[0], commentUsage);
2705
- const given = positionals.slice(1).join(" ") || undefined;
2859
+ const { number, rest } = await targetIssue(positionals, values.repo, commentUsage);
2860
+ const given = rest.join(" ") || undefined;
2706
2861
  const text = await noteText({ message: given, file: values.file ?? (given === undefined ? "-" : undefined) });
2707
2862
  if (text === undefined)
2708
2863
  fail(`nothing to comment
@@ -2712,11 +2867,11 @@ ${commentUsage}`);
2712
2867
  console.log(`commented on #${number}`);
2713
2868
  return 0;
2714
2869
  }
2715
- var fixedUsage = `ft fixed <n> [commit]...
2870
+ var fixedUsage = `ft fixed [<n>] [commit]...
2716
2871
 
2717
2872
  Comments "Fixed in <sha>: <message>" on issue <n> and closes it, naming each commit given as "Fixed in <a>, <b> and <c>".
2718
2873
  Without a commit it takes those on origin's default branch whose message names #<n>, and says which, or HEAD when none does.
2719
- The message defaults to the subject of the first commit. Every open issue listing \`- [ ] #<n>\` in its checklist gets that line ticked. An issue with boxes left is refused, as a partly done issue stays open, unless --tick ticks them first.
2874
+ Without <n> it takes the one open issue this session holds (\`ft take\`). The message defaults to the subject of the first commit. Every open issue listing \`- [ ] #<n>\` in its checklist gets that line ticked. An issue with boxes left is refused, as a partly done issue stays open, unless --tick ticks them first.
2720
2875
 
2721
2876
  Exits 0 when it closed the issue, 1 when the issue is already closed, has boxes left or Forgejo refuses, 2 on a usage error.`;
2722
2877
  var fixedOptions = {
@@ -2761,8 +2916,8 @@ async function tickListings(closed, repo) {
2761
2916
  async function fixed(args) {
2762
2917
  const parsed = parse(args, fixedUsage, fixedOptions);
2763
2918
  const { values, positionals } = parsed;
2764
- const number = issueNumber(positionals[0], fixedUsage);
2765
- const commits = await fixingCommits(number, positionals.slice(1));
2919
+ const { number, rest } = await targetIssue(positionals, values.repo, fixedUsage);
2920
+ const commits = await fixingCommits(number, rest);
2766
2921
  const found = await getIssue(number, values.repo);
2767
2922
  if (found.state === "closed")
2768
2923
  fail(`#${number} is already closed`, 1, runHint(`ft reopen ${number}`, "reopen it"));
@@ -3647,8 +3802,7 @@ Lists recent runs with what tea's own listing leaves empty: workflow, ref, durat
3647
3802
  Exits 0 when it listed them, 1 when Forgejo or git cannot be read, 2 on a usage error.`;
3648
3803
  var DEFAULT_LIMIT = 10;
3649
3804
  var options8 = {
3650
- limit: { ...limitOptions(DEFAULT_LIMIT).limit, short: "n" },
3651
- full: limitOptions(DEFAULT_LIMIT).full,
3805
+ ...limitOptions(DEFAULT_LIMIT),
3652
3806
  sha: { type: "string", short: "s", description: "only the runs of this commit" },
3653
3807
  workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml" },
3654
3808
  json: jsonOption(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.12.0",
5
5
  "description": "ft: Forgejo CI runs, logs, releases and issue checklists from the terminal, through tea.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -28,6 +28,6 @@
28
28
  "ft": "$npm_execpath src/cli.ts"
29
29
  },
30
30
  "devDependencies": {
31
- "@kaynooo/cli-kit": "0.15.0"
31
+ "@kaynooo/cli-kit": "0.19.0"
32
32
  }
33
33
  }