A note-taking app inspired by nb
1import { Command } from "@cliffy/command";
2import { basename } from "@std/path";
3import { Hsh } from "../hsh.ts";
4
5function register(cmd: Command, hsh: Hsh) {
6 cmd
7 .command("import", "import an existing file")
8 .arguments("<...paths:file>")
9 .option("-t, --target <target:string>", "target path")
10 .action(({ target }, ...paths) => {
11 if (paths.length === 0) return;
12 const t = target != null
13 ? hsh.parse(target)
14 : hsh.getNotebook().newPath();
15 if (t.entry) {
16 throw new Error("target must be a folder, not a document");
17 }
18 for (const p of paths) {
19 Deno.copyFileSync(p, t.withEntry(basename(p)).getAbsolutePath());
20 }
21 hsh.emitNotebookChanged(
22 t.notebook,
23 `[hsh]: imported ${
24 paths.length === 1 ? paths[0] : `${paths.length} items`
25 }`,
26 );
27 });
28}
29
30export default { register };