import { Command } from "@cliffy/command"; import { basename } from "@std/path"; import { Hsh } from "../hsh.ts"; function register(cmd: Command, hsh: Hsh) { cmd .command("import", "import an existing file") .arguments("<...paths:file>") .option("-t, --target ", "target path") .action(({ target }, ...paths) => { if (paths.length === 0) return; const t = target != null ? hsh.parse(target) : hsh.getNotebook().newPath(); if (t.entry) { throw new Error("target must be a folder, not a document"); } for (const p of paths) { Deno.copyFileSync(p, t.withEntry(basename(p)).getAbsolutePath()); } hsh.emitNotebookChanged( t.notebook, `[hsh]: imported ${ paths.length === 1 ? paths[0] : `${paths.length} items` }`, ); }); } export default { register };