more notes

This commit is contained in:
Tyrel Souza 2017-11-20 21:59:31 -05:00
parent c031aabdb5
commit 11cd3b5b68
4 changed files with 73 additions and 47 deletions

35
app.js
View File

@ -3,21 +3,32 @@ const _ = require('lodash');
const yargs = require('yargs'); const yargs = require('yargs');
const notes = require('./notes.js'); 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 command = argv._[0]
var noteTitle = argv.title; var noteTitle = argv.title;
var logNote = (note) => {
console.log(`Title: ${note.title}`);
console.log(`Body: ${note.body}`);
}
switch (command){ switch (command){
case 'add': case 'add':
var note = notes.addNote(noteTitle, argv.body); var note = notes.addNote(noteTitle, argv.body);
if (note){ if (note){
logNote(note); notes.logNote(note);
} else { } else {
console.log(`No note added: ${noteTitle} exists already.`); console.log(`No note added: ${noteTitle} exists already.`);
} }
@ -25,10 +36,10 @@ switch (command){
case 'list': case 'list':
var allNotes = notes.getAll(); var allNotes = notes.getAll();
if (allNotes){ if (allNotes){
console.log("All Notes:"); console.log(`All Notes (${allNotes.length}):`);
for (var idx in allNotes){ allNotes.forEach((note) =>{
console.log(`Title: ${allNotes[idx].title}`) notes.logNote(note);
} });
} else { } else {
console.log("No notes found."); console.log("No notes found.");
} }
@ -36,7 +47,7 @@ switch (command){
case 'read': case 'read':
var note = notes.getNote(noteTitle); var note = notes.getNote(noteTitle);
if(note){ if(note){
logNote(note); notes.logNote(note);
} else { } else {
console.log(`Can't find "${noteTitle}"`); console.log(`Can't find "${noteTitle}"`);
} }

View File

@ -1 +1 @@
[{"title":"Tuesday","body":"sucks"},{"title":"modday","body":"sucks"}] [{"title":"Tuesday","body":"sucks"},{"title":"Node","body":"JS:"}]

View File

@ -43,14 +43,19 @@ var getNote = (title) => {
} }
var removeNote = (title) => { var removeNote = (title) => {
console.log("Deleting", title);
var notes = fetchNotes(); var notes = fetchNotes();
filteredNotes = notes.filter((note) => note.title !== title); filteredNotes = notes.filter((note) => note.title !== title);
saveNotes(filteredNotes); saveNotes(filteredNotes);
return notes.length !== filteredNotes.length; return notes.length !== filteredNotes.length;
} }
var logNote = (note) => {
console.log(`Title: ${note.title}`);
console.log(`Body: ${note.body}`);
}
module.exports = { module.exports = {
logNote,
addNote, addNote,
getAll, getAll,
getNote, getNote,

10
playground/debugging.js Normal file
View File

@ -0,0 +1,10 @@
var person = {
name: "tyrel"
}
debugger;
person.age = 29;
person.name = 'Tyrel';
console.log(person);