more notes
This commit is contained in:
parent
c031aabdb5
commit
11cd3b5b68
91
app.js
91
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");
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
[{"title":"Tuesday","body":"sucks"},{"title":"modday","body":"sucks"}]
|
||||
[{"title":"Tuesday","body":"sucks"},{"title":"Node","body":"JS:"}]
|
17
notes.js
17
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,
|
||||
}
|
||||
|
10
playground/debugging.js
Normal file
10
playground/debugging.js
Normal file
@ -0,0 +1,10 @@
|
||||
var person = {
|
||||
name: "tyrel"
|
||||
}
|
||||
debugger;
|
||||
|
||||
person.age = 29;
|
||||
|
||||
person.name = 'Tyrel';
|
||||
|
||||
console.log(person);
|
Loading…
Reference in New Issue
Block a user