diff options
Diffstat (limited to 'src/command.js')
| -rw-r--r-- | src/command.js | 34 |
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(); |
