File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,21 @@ yargs.command({
47
47
}
48
48
} )
49
49
50
+ yargs . command ( {
51
+ command : 'remove' ,
52
+ describe : 'Removing a note' ,
53
+ builder : {
54
+ title : {
55
+ describe : 'note title' ,
56
+ demandOption : true ,
57
+ type : 'string'
58
+ }
59
+ } ,
60
+ handler : ( argv ) => {
61
+ console . log ( notesStorage . removeNote ( argv . title ) )
62
+ }
63
+ } )
64
+
50
65
yargs . parse ( )
51
66
52
67
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ class NotesController {
59
59
console . log ( chalk . bgRed ( 'ERROR: ' ) , chalk . red ( 'this title already exist' ) )
60
60
}
61
61
}
62
+
63
+ removeNote ( title ) {
64
+ this . fetchJSON ( )
65
+ let notesCount = this . notes . data . length
66
+ this . notes . data = this . notes . data . filter ( note => note . title !== title )
67
+ this . dumpJson ( )
68
+ return notesCount === this . notes . data . length ? chalk . red ( 'title not found' ) : chalk . green ( 'note deleted successfully' )
69
+ }
62
70
}
63
71
64
72
module . exports = NotesController
You can’t perform that action at this time.
0 commit comments