// `umtool share [] [--take ] [--site ] [--json]` (lane // output-modes): a clip's SHARE LINE -- the CLI twin of the take panel's and // Play's **Copy share line** (GET /api/report/share-line). The clip named, else // the cut's (or the take's) first. shareLine.mjs builds it. // // Plain ESM: the CLI runs it under bare node. import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { projectShareLine } from "./shareLine.mjs"; import { siteOriginOf } from "./quickClip.mjs"; export const SHARE_USAGE = [ "usage: umtool share [] [--take ] [--site ] [--json]", " a clip's share line: its platform page at the first second it plays (YouTube t=, Rumble start=) and its", " moment on the archive (the manifest's siteOrigin, or --site's), a Rumble folder id as the embed id the", " archive serves. The clip named, else the first; --take: the take's cut. --json: {clip, seconds, platform, archive, text}.", ].join("\n"); class CliError extends Error {} /** * @param {string[]} args the words after `share` * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void, sitesDir?: string }} [o] * @returns {Promise} */ export async function shareCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), sitesDir } = {}) { try { const words = []; const flags = new Map(); for (let i = 0; i < args.length; i += 1) { const a = args[i]; if (a === "--take" || a === "--site") { if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); flags.set(a, args[++i]); } else if (a === "--json" || a === "--help") flags.set(a, true); else if (a.startsWith("--")) throw new CliError(`unknown flag ${a}`); else words.push(a); } if (flags.has("--help") || !words.length || words.length > 2) { (flags.has("--help") ? out : err)(SHARE_USAGE); return flags.has("--help") ? 0 : 2; } const r = await resolveProject(words[0], root); if (r.ambiguous) throw new CliError(`"${words[0]}" is the name of ${r.ambiguous.length} projects — pass its id`); if (!r.project) throw new CliError(`no project matches "${words[0]}"`); const origin = flags.has("--site") ? await siteOriginOf(String(flags.get("--site")), sitesDir ? { sitesDir } : {}) : undefined; const line = await projectShareLine(r.project, { clip: words[1] ?? null, take: flags.get("--take") ?? null, ...(origin !== undefined ? { origin } : {}) }); if (flags.has("--json")) out(JSON.stringify(line, null, 2)); else out(line.text || `${line.clip}: no platform page or archive to link`); return 0; } catch (e) { err(e instanceof Error ? e.message : String(e)); return e instanceof CliError || (e instanceof Error && e.constructor?.name === "CliError") ? 2 : 1; } }