feat(tasktree): import MDTODO files and reports
This commit is contained in:
@@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises";
|
||||
|
||||
import type { TaskStatus, TaskTreeCommand } from "../../internal/tasktree/contracts.ts";
|
||||
import { createTaskTreeDispatcher } from "../../internal/tasktree/dispatcher.ts";
|
||||
import { loadMdtodoImportPayload } from "../../internal/tasktree/mdtodo-import.ts";
|
||||
import { taskTreeRuntime } from "../../internal/tasktree/runtime.ts";
|
||||
|
||||
export async function runTaskTreeCli(argv: string[], env: Record<string, string | undefined> = process.env) {
|
||||
@@ -28,6 +29,7 @@ function help() {
|
||||
"hwlab-cli tasktree task create|update|delete --group ID|--task ID [--parent ID] --title TEXT --start ISO --due ISO --status STATUS",
|
||||
"hwlab-cli tasktree milestone create --group ID [--task ID] --title TEXT --at ISO",
|
||||
"hwlab-cli tasktree report create --task ID --title TEXT (--body TEXT|--body-file PATH)",
|
||||
"hwlab-cli tasktree import mdtodo --file PATH [--name TEXT] [--dry-run] [--overapi]",
|
||||
"hwlab-cli tasktree timeline --group ID [--overapi]",
|
||||
"hwlab-cli tasktree workflow start --task ID"
|
||||
],
|
||||
@@ -48,6 +50,7 @@ async function commandFrom(parsed: Parsed): Promise<TaskTreeCommand> {
|
||||
if (group === "task" && action === "delete") return { operation: "task.delete", taskId: required(parsed, "task") };
|
||||
if (group === "milestone" && action === "create") return { operation: "milestone.create", groupId: required(parsed, "group"), taskId: parsed.values.task, title: required(parsed, "title"), occursAt: required(parsed, "at") };
|
||||
if (group === "report" && action === "create") return { operation: "report.create", taskId: required(parsed, "task"), title: required(parsed, "title"), body: parsed.values.body ?? await readFile(required(parsed, "body-file"), "utf8"), status: parsed.values.status };
|
||||
if (group === "import" && action === "mdtodo") return { operation: "mdtodo.import", ...await loadMdtodoImportPayload(required(parsed, "file"), { groupName: parsed.values.name, dryRun: parsed.flags.has("dry-run") }) };
|
||||
if (group === "workflow" && action === "start") return { operation: "workflow.start", taskId: required(parsed, "task") };
|
||||
throw new Error(`unsupported TaskTree command: ${group} ${action}`.trim());
|
||||
}
|
||||
@@ -61,12 +64,13 @@ async function overApi(command: TaskTreeCommand, env: Record<string, string | un
|
||||
return { ...(body as object), transport: "api", httpStatus: response.status };
|
||||
}
|
||||
|
||||
type Parsed = { positionals: string[]; values: Record<string, string>; overapi: boolean; help: boolean };
|
||||
type Parsed = { positionals: string[]; values: Record<string, string>; flags: Set<string>; overapi: boolean; help: boolean };
|
||||
function parse(argv: string[]): Parsed {
|
||||
const parsed: Parsed = { positionals: [], values: {}, overapi: false, help: false };
|
||||
const parsed: Parsed = { positionals: [], values: {}, flags: new Set(), overapi: false, help: false };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const token = argv[index];
|
||||
if (token === "--overapi") parsed.overapi = true;
|
||||
else if (token === "--dry-run") parsed.flags.add("dry-run");
|
||||
else if (token === "--help" || token === "-h") parsed.help = true;
|
||||
else if (token.startsWith("--")) {
|
||||
const key = token.slice(2);
|
||||
|
||||
Reference in New Issue
Block a user