summaryrefslogtreecommitdiff
path: root/src/command.js
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2025-11-09 14:19:26 +0100
committerLeo Goetz <dev@leogtz.de>2025-11-09 14:19:26 +0100
commit789d28b83af165258dc7e8b3a44bbd2d48fcc370 (patch)
treee98ef728fb42a7bc03aef6d6a601e0533a4961b3 /src/command.js
parent16a0e9a9d2c24af28142ed3420ef6cb373c454f7 (diff)
added crud functionality with json file as a db
Diffstat (limited to 'src/command.js')
-rw-r--r--src/command.js34
1 files changed, 28 insertions, 6 deletions
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 <filter>",
@@ -36,7 +49,10 @@ yargs(hideBin(process.argv))
type: "string",
});
},
- async (argv) => {},
+ async (argv) => {
+ const matches = await findNotes(argv.filter);
+ listNotes(matches);
+ },
)
.command(
"remove <id>",
@@ -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();