const fs = require('fs'); const _ = require('lodash'); const yargs = require('yargs'); const notes = require('./notes.js'); const argv = yargs.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); break; default: console.log("Command not found"); }