1
0
CompleteNodeJS/notes-app/app.js

64 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-11 18:15:16 +00:00
const chalk = require('chalk');
const yargs = require('yargs');
const notes = require('./notes.js');
// Customize yargs version
yargs.version('1.1.0');
// Create add command
yargs.command({
command: 'add',
describe: 'Add a new note',
builder: {
title: {
describe: 'Note title',
demandOption: true,
type: 'string'
},
body: {
describe: 'Note body',
demandOption: true,
type: 'string'
}
},
2019-08-11 18:56:43 +00:00
handler(argv) {
2019-08-11 18:15:16 +00:00
notes.addNote(argv.title, argv.body);
}
});
// Create remove command
yargs.command({
command: 'remove',
describe: 'Remove a note',
builder: {
title: {
describe: 'Note title',
demandOption: true,
type: 'string'
}
},
2019-08-11 18:56:43 +00:00
handler(argv) {
2019-08-11 18:15:16 +00:00
notes.removeNote(argv.title);
}
});
// Create list command
yargs.command({
command: 'list',
describe: 'List notes',
2019-08-11 18:56:43 +00:00
handler() {
2019-08-11 18:15:16 +00:00
console.log('Listing out all notes');
}
});
// Create read command
yargs.command({
command: 'read',
describe: 'Read a note',
2019-08-11 18:56:43 +00:00
handler() {
2019-08-11 18:15:16 +00:00
console.log('Reading a note');
}
});
yargs.parse();