summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNullspoon <nullspoon@iohq.net>2014-09-30 23:21:32 -0600
committerNullspoon <nullspoon@iohq.net>2014-09-30 23:21:32 -0600
commit0dffc9bbb2ff39e34a5ae9a1faf63f668b055c48 (patch)
tree763838e3237b2828fe686f64fe3463ae86ab2610
parent296964fac1f787422a1d13e70a01c4a9d78e1805 (diff)
downloadnoteless-0dffc9bbb2ff39e34a5ae9a1faf63f668b055c48.tar.gz
noteless-0dffc9bbb2ff39e34a5ae9a1faf63f668b055c48.tar.xz
Implemented rm command
Can delete notes now by name. Updated help text and README
-rw-r--r--README.md1
-rw-r--r--TODO.mdown3
-rw-r--r--src/lib/note.cpp9
-rw-r--r--src/lib/note.h1
-rw-r--r--src/lib/note_list.cpp18
-rw-r--r--src/lib/note_list.h1
-rw-r--r--src/main.cpp4
7 files changed, 36 insertions, 1 deletions
diff --git a/README.md b/README.md
index 2a4c5ae..ed9249b 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/TODO.mdown b/TODO.mdown
index 9feff30..985d7bf 100644
--- a/TODO.mdown
+++ b/TODO.mdown
@@ -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 );

Generated by cgit