A note-taking app inspired by nb
at main 43 lines 1.3 kB view raw
1import { Command } from "@cliffy/command"; 2import { addFolder, moveItem, removeFolder } from "../folders.ts"; 3import { Hsh } from "../hsh.ts"; 4 5function register(cmd: Command, hsh: Hsh) { 6 cmd 7 .command("move", "move a note") 8 .alias("mv") 9 .alias("mi") 10 .arguments("<origin:string> <destination:string>") 11 .action(async (_opts, origin, destination) => { 12 const source = await hsh.resolve(origin); 13 const target = hsh.parse(destination, false); 14 if (source.entry != null && target.entry == null) { 15 target.entry = source.entry; 16 } 17 await moveItem(source, target, hsh); 18 }); 19 cmd.command("folder", getFolderCommands(hsh)); 20} 21 22function getFolderCommands(hsh: Hsh) { 23 return new Command() 24 .description("add, remove and move folders") 25 .action(function () { 26 this.showHelp(); 27 }) 28 .command("add", "add folder") 29 .alias("a") 30 .arguments("<path:string>") 31 .action(async (_options, path) => { 32 await addFolder(hsh.parse(path, false), hsh); 33 }) 34 .command("remove", "remove a folder") 35 .alias("rm") 36 .option("-f, --force", "force removal", { default: false }) 37 .arguments("<path:string>") 38 .action(async ({ force }, path) => { 39 await removeFolder(hsh.parse(path), force, hsh); 40 }); 41} 42 43export default { register };