1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| const yargs = require('yargs'); const nodes = require('./nodes.js')
const argv = yargs .command('add','add a new note',{ title:{ describe:'Title of note', demand:true, alias:'t' }, body:{ describe:'Body of note', demand:true, alias:'b' } }) .command('list','List all notes') .command('read','Read a note',{ title:{ describe:'Title of note', demand:true, alias:'t' } }) .command('remove','Remove a note',{ title:{ describe:'Title of note', demand:true, alias:'t' } }) .help() .argv; var command = process.argv[2];
if(command==='add'){ var note = nodes.addNote(argv.title,argv.body); if(note){ console.log('add success'); console.log(`title:${note.title}`); console.log(`body:${note.body}`); } }else if(command === 'list'){ var allnotes = nodes.getAll(); allnotes.forEach((note)=>{ console.log(note)}); }else if(command =='read'){ var note = nodes.getNote(argv.title); if(note){ console.log('find'); console.log(`title:${note.title}`); console.log(`body:${note.body}`); }else{ console.log('note not found'); } }else if(command=='remove'){ var noteRemoved = nodes.removeNote(argv.title); var message = noteRemoved?'Note was removed':'note not found'; console.log(message); }else{ console.log('command not find'); }
|