diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | TODO.mdown | 3 | ||||
-rw-r--r-- | src/lib/note.cpp | 9 | ||||
-rw-r--r-- | src/lib/note.h | 1 | ||||
-rw-r--r-- | src/lib/note_list.cpp | 18 | ||||
-rw-r--r-- | src/lib/note_list.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 4 |
7 files changed, 36 insertions, 1 deletions
@@ -34,4 +34,5 @@ there), add ~/bin to your path, and you should be good to go. the lines that match along with their line numbers and files from which they came. * **help**: Displays the help text. +* **rm**: Deletes the specified note @@ -21,4 +21,5 @@ completed when they're complete. if note name is the first argument * Write "init" command to create the configured notes directory if it doesn't exist. -* Implemente better subdirectory handling when listing notes +* Implement better subdirectory handling when listing notes +* Implement rm action to delete notes diff --git a/src/lib/note.cpp b/src/lib/note.cpp index dac08ea..1e6a102 100644 --- a/src/lib/note.cpp +++ b/src/lib/note.cpp @@ -214,6 +214,15 @@ string note::get_extension() { } /** + * Deletes the current note instance from the filesystem. + * + * @return int Success or failure + */ +int note::rm() { + return remove( _path.out().c_str() ); +} + +/** * Gets the filename of the current note instance without its extension. * * @return string Note filename without extension diff --git a/src/lib/note.h b/src/lib/note.h index 011722b..8dc63f2 100644 --- a/src/lib/note.h +++ b/src/lib/note.h @@ -44,6 +44,7 @@ class note { note( string, string ); int create( string ); int edit( string ); + int rm(); void read(); string itos( int ); string get_current_date_time(); diff --git a/src/lib/note_list.cpp b/src/lib/note_list.cpp index afb2978..dcd39f4 100644 --- a/src/lib/note_list.cpp +++ b/src/lib/note_list.cpp @@ -169,6 +169,24 @@ int note_list::cat_note( string note_name, vector<string>* pbody ) { } /** + * Deletes the specified note + * + * @param string note_name Name of the note to be deleted + * + * @return int Exit code (1 = error, 0 = success) + */ +int note_list::rm( string note_name ) { + int id = find_note_id( note_name ); + if( id == -1 ) { + cout << "Note \"" << note_name << "\" does not exist." << endl; + return 1; + } else { + notes[id].rm(); + } + return 0; +} + +/** * TODO */ vector<string> note_list::find( bool case_sensitive, string term ) { diff --git a/src/lib/note_list.h b/src/lib/note_list.h index 03cd3e2..3e3a2c6 100644 --- a/src/lib/note_list.h +++ b/src/lib/note_list.h @@ -39,6 +39,7 @@ class note_list { int add( string, string ); int create( string, string ); int edit( string, string ); + int rm( string ); vector<string> enum_names(); vector<string> find( bool, string ); int cat_note( string, vector<string>* ); diff --git a/src/main.cpp b/src/main.cpp index cfc5dd7..bbfe566 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ int get_help() { " new <note> Creates the specified note and opens for editing.\n" " edit <note> Opens the specified note for editing.\n" " find <term> Performs a case-insensitive search of all notes for the\n" + " rm <note> Deletes the specified note.\n" " given search term.\n" " help Displays this help text\n" " ls,list Lists all notes in note directory.\n"; @@ -168,6 +169,9 @@ int main( int argc, char** argv ) { } else if( arg == "edit" ) { string name = argv[i + 1]; return list.edit( editor, name ); + } else if( arg == "rm" ) { + string name = argv[i + 1]; + return list.rm( name ); } else if( arg == "find" ) { string term = argv[i + 1]; return search_notes( list, term ); |