summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.rs16
-rw-r--r--src/main.rs23
2 files changed, 31 insertions, 8 deletions
diff --git a/src/db.rs b/src/db.rs
index 6c1214b..93d73a8 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -4,6 +4,8 @@ use rusqlite;
 use std::sync::mpsc;
 use std::time;
 
+const DB_PATH: &str = "/tmp/clinte.db";
+
 #[derive(Debug)]
 pub struct Post {
     id: u32,
@@ -20,8 +22,8 @@ pub struct Conn {
 
 #[derive(Debug)]
 pub enum Cmd {
-    Create,
-    Update,
+    Create(Post),
+    Update(Post),
     Disconnect,
     NOOP,
 }
@@ -31,7 +33,7 @@ impl Conn {
         let start = time::Instant::now();
         info!("Connecting to database");
         let conn = rusqlite::Connection::open_with_flags(
-            "/tmp/db.sql",
+            DB_PATH,
             rusqlite::OpenFlags::SQLITE_OPEN_FULL_MUTEX
                 | rusqlite::OpenFlags::SQLITE_OPEN_CREATE
                 | rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE,
@@ -40,7 +42,7 @@ impl Conn {
 
         conn.execute(
             "CREATE TABLE IF NOT EXISTS posts (
-            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+            id INTEGER PRIMARY KEY NOT NULL,
             title TEXT NOT NULL,
             author TEXT NOT NULL,
             body TEXT NOT NULL
@@ -66,10 +68,10 @@ impl Conn {
 }
 
 impl Cmd {
-    pub fn new(txt: &str) -> Self {
+    pub fn new(txt: &str, post: Post) -> Self {
         match txt {
-            "create" => Cmd::Create,
-            "update" => Cmd::Update,
+            "create" => Cmd::Create(post),
+            "update" => Cmd::Update(post),
             "disconnect" => Cmd::Disconnect,
             _ => Cmd::NOOP,
         }
diff --git a/src/main.rs b/src/main.rs
index 6c0d957..3f93d92 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,31 @@
+use clap;
 use log::info;
 use std::sync::mpsc;
+use std::time;
 
 mod db;
 mod logging;
 
 fn main() {
+    let arg_matches = clap::App::new("clinte")
+        .version(clap::crate_version!())
+        .author("Ben Morrison (gbmor)")
+        .about("Command-line community notices system")
+        .subcommand(clap::SubCommand::with_name("list").about("Display notices"))
+        .subcommand(clap::SubCommand::with_name("post").about("Post a new notice"))
+        .subcommand(
+            clap::SubCommand::with_name("update")
+                .about("Update a notice you've posted")
+                .arg(clap::Arg::with_name("id").help("Numeric ID of the post")),
+        )
+        .subcommand(
+            clap::SubCommand::with_name("delete")
+                .about("Delete a notice you've posted")
+                .arg(clap::Arg::with_name("id").help("Numeric ID of the post")),
+        )
+        .get_matches();
+
+    let start = time::Instant::now();
     logging::init();
     info!("clinte starting up!");
     println!("clinte-0.1-dev");
@@ -13,5 +34,5 @@ fn main() {
     let (_tx, rx) = mpsc::channel::<db::Cmd>();
     let db = db::Conn::new(rx);
 
-    println!("{:?}", db);
+    info!("Startup completed in {:?}ms", start.elapsed().as_millis());
 }