working on command line args
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 8 Dec 2020 05:11:48 +0000 (00:11 -0500)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 8 Dec 2020 05:11:48 +0000 (00:11 -0500)
README.md [new file with mode: 0644]
main.cpp

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..9f4deb7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# Taskasaur
+
+A very simple kanban style todolist with vim keybindings.
+
+Boards are stored in markdown files.
index 791d86e..bb33673 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,9 +1,57 @@
-#include <ncurses.h>
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
 #include <string>
+#include <ncurses.h>
 using namespace std;
 
-int main(int argc, char ** argv) {
+bool file_exists(const char* file_name) {
+    ifstream test_file(file_name);
+    return (bool)test_file;
+}
+
+int main(int argc, char** argv) {
     
+    // read command line args
+    if (argc < 2) {
+        cout << "Taskasaur options\n-o [board_name]\n-n [new_board+name]";
+        return 1;
+    }
+   
+    int flag; 
+    while ((flag = getopt(argc, argv, "o:n:")) != -1) {
+        if (flag == 'o') {
+
+            char* file_name = optarg;
+            printf("Opening %s\n", file_name);
+
+            // check if file exists
+            if (!file_exists(file_name)) {
+                printf("%s does not exist.\n", file_name);
+                return 1;
+            }
+
+        } else if (flag == 'n') {
+
+            char* new_file_name = optarg;
+            printf("Creating %s\n", new_file_name);
+
+            if (file_exists(new_file_name)) {
+                printf("The board %s already exist.\n", new_file_name);
+                return 1;
+            }
+
+            ofstream new_file;
+            new_file.open(new_file_name);
+            new_file << "# Taskasaur\n";
+            new_file.close();
+
+        }
+    }   
+    return 0;
+
+   
+    // start ncurses 
     initscr();
     cbreak();
     /* raw(); */
@@ -46,7 +94,6 @@ int main(int argc, char ** argv) {
         } 
         if (ch == 113) break; // q for quit
 
-
         box(win, 0, 0);
         wattron(win,COLOR_PAIR(1));
         wattron(win, A_BOLD);