From 789d28b83af165258dc7e8b3a44bbd2d48fcc370 Mon Sep 17 00:00:00 2001 From: Leo Goetz Date: Sun, 9 Nov 2025 14:19:26 +0100 Subject: added crud functionality with json file as a db --- src/command.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/command.js') diff --git a/src/command.js b/src/command.js index 20a23b2..c022c81 100644 --- a/src/command.js +++ b/src/command.js @@ -1,5 +1,13 @@ import yargs from "yargs"; import { hideBin } from "yargs/helpers"; +import { + findNotes, + getAllNotes, + newNote, + removeAllNotes, + removeNote, +} from "./notes.js"; +import { listNotes } from "./utils.js"; yargs(hideBin(process.argv)) .command( @@ -11,8 +19,10 @@ yargs(hideBin(process.argv)) description: "The content of the note to create", }); }, - (argv) => { - console.log(argv.note); + async (argv) => { + const tags = argv.tags ? argv.tags.split(",") : []; + const note = await newNote(argv.note, tags); + console.log("New Note: ", note); }, ) .option("tags", { @@ -24,7 +34,10 @@ yargs(hideBin(process.argv)) "all", "get all notes", () => {}, - async (argv) => {}, + async () => { + const notes = await getAllNotes(); + listNotes(notes); + }, ) .command( "find ", @@ -36,7 +49,10 @@ yargs(hideBin(process.argv)) type: "string", }); }, - async (argv) => {}, + async (argv) => { + const matches = await findNotes(argv.filter); + listNotes(matches); + }, ) .command( "remove ", @@ -47,7 +63,10 @@ yargs(hideBin(process.argv)) description: "The id of the note you want to remove", }); }, - async (argv) => {}, + async (argv) => { + const id = await removeNote(argv.id); + console.log(id); + }, ) .command( "web [port]", @@ -65,7 +84,10 @@ yargs(hideBin(process.argv)) "clean", "remove all notes", () => {}, - async (argv) => {}, + async (argv) => { + await removeAllNotes(); + console.log("db reseted"); + }, ) .demandCommand(1) .parse(); -- cgit v1.3