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 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);
notes.logNote(note);
} else {
console.log(`No note added: ${noteTitle} exists already.`);
}
@ -25,10 +36,10 @@ switch (command){
case 'list':
var allNotes = notes.getAll();
if (allNotes){
console.log("All Notes:");
for (var idx in allNotes){
console.log(`Title: ${allNotes[idx].title}`)
}
console.log(`All Notes (${allNotes.length}):`);
allNotes.forEach((note) =>{
notes.logNote(note);
});
} else {
console.log("No notes found.");
}
@ -36,7 +47,7 @@ switch (command){
case 'read':
var note = notes.getNote(noteTitle);
if(note){
logNote(note);
notes.logNote(note);
} else {
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) => {
console.log("Deleting", title);
var notes = fetchNotes();
filteredNotes = notes.filter((note) => note.title !== title);
saveNotes(filteredNotes);
return notes.length !== filteredNotes.length;
}
var logNote = (note) => {
console.log(`Title: ${note.title}`);
console.log(`Body: ${note.body}`);
}
module.exports = {
logNote,
addNote,
getAll,
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);