diff --git a/app.js b/app.js index d1a2fe6..7fa2f1a 100644 --- a/app.js +++ b/app.js @@ -3,50 +3,61 @@ const _ = require('lodash'); const yargs = require('yargs'); const notes = require('./notes.js'); +var titleOptions = { + describe: 'Title of note', + demand: true, + alias: "t" +} +var bodyOptions = { + describe: 'Body of note', + demand: true, + alias: 'b' +} -const argv = yargs.argv; +const argv = yargs + .command('add', 'Add a new note', { title: titleOptions, body: bodyOptions }) + .command('list', 'List all notes') + .command('read', 'Read a note', { title: titleOptions }) + .command('remove', 'Remove a note', { title: titleOptions }) + .help() + .argv; var command = argv._[0] var noteTitle = argv.title; -var logNote = (note) => { - console.log(`Title: ${note.title}`); - console.log(`Body: ${note.body}`); -} - switch (command){ - case 'add': - var note = notes.addNote(noteTitle, argv.body); - if (note){ - logNote(note); - } else { - console.log(`No note added: ${noteTitle} exists already.`); - } - break; - case 'list': - var allNotes = notes.getAll(); - if (allNotes){ - console.log("All Notes:"); - for (var idx in allNotes){ - console.log(`Title: ${allNotes[idx].title}`) - } - } else { - console.log("No notes found."); - } - break; - case 'read': - var note = notes.getNote(noteTitle); - if(note){ - logNote(note); - } else { - console.log(`Can't find "${noteTitle}"`); - } - break; - case 'remove': - var noteRemoved = notes.removeNote(noteTitle); - var message = noteRemoved ? `"${noteTitle}" was removed` : "No note removed"; - console.log(message); + case 'add': + var note = notes.addNote(noteTitle, argv.body); + if (note){ + notes.logNote(note); + } else { + console.log(`No note added: ${noteTitle} exists already.`); + } + break; + case 'list': + var allNotes = notes.getAll(); + if (allNotes){ + console.log(`All Notes (${allNotes.length}):`); + allNotes.forEach((note) =>{ + notes.logNote(note); + }); + } else { + console.log("No notes found."); + } + break; + case 'read': + var note = notes.getNote(noteTitle); + if(note){ + notes.logNote(note); + } else { + console.log(`Can't find "${noteTitle}"`); + } + break; + case 'remove': + var noteRemoved = notes.removeNote(noteTitle); + var message = noteRemoved ? `"${noteTitle}" was removed` : "No note removed"; + console.log(message); - break; - default: - console.log("Command not found"); + break; + default: + console.log("Command not found"); } diff --git a/notes-data.json b/notes-data.json index 4d866dc..fb5b9fb 100644 --- a/notes-data.json +++ b/notes-data.json @@ -1 +1 @@ -[{"title":"Tuesday","body":"sucks"},{"title":"modday","body":"sucks"}] \ No newline at end of file +[{"title":"Tuesday","body":"sucks"},{"title":"Node","body":"JS:"}] \ No newline at end of file diff --git a/notes.js b/notes.js index 3f25f3c..9ef38d8 100644 --- a/notes.js +++ b/notes.js @@ -43,16 +43,21 @@ var getNote = (title) => { } var removeNote = (title) => { - console.log("Deleting", title); var notes = fetchNotes(); filteredNotes = notes.filter((note) => note.title !== title); saveNotes(filteredNotes); return notes.length !== filteredNotes.length; } -module.exports = { - addNote, - getAll, - getNote, - removeNote, +var logNote = (note) => { + console.log(`Title: ${note.title}`); + console.log(`Body: ${note.body}`); +} + +module.exports = { + logNote, + addNote, + getAll, + getNote, + removeNote, } diff --git a/playground/debugging.js b/playground/debugging.js new file mode 100644 index 0000000..7753be9 --- /dev/null +++ b/playground/debugging.js @@ -0,0 +1,10 @@ +var person = { + name: "tyrel" +} +debugger; + +person.age = 29; + +person.name = 'Tyrel'; + +console.log(person);