about summary refs log tree commit diff stats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-09-05 03:25:45 -0400
committerBen Morrison <ben@gbmor.dev>2019-09-05 03:25:45 -0400
commitfd2f77093812a19536487bbf6928d02fb9b1f372 (patch)
treea7b52eab4c41ef4fc039a5f80d01eeedae2d1985 /src/main.rs
parent567a66d30fb86ad144e3deec256e27d05a611c2d (diff)
downloadclinte-fd2f77093812a19536487bbf6928d02fb9b1f372.tar.gz
letting errors flow up
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index f003a5b..e2f793b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ mod logging;
 mod posts;
 mod user;
 
-fn main() {
+fn main() -> error::Result<()> {
     let arg_matches = clap::App::new("clinte")
         .version(clap::crate_version!())
         .author("Ben Morrison (gbmor)")
@@ -24,7 +24,7 @@ fn main() {
         .get_matches();
 
     let start = time::Instant::now();
-    logging::init();
+    logging::init()?;
     info!("clinte starting up!");
     println!("clinte v{}", clap::crate_version!());
     println!("a community notices system");
@@ -36,24 +36,26 @@ fn main() {
 
     if arg_matches.subcommand_matches("post").is_some() {
         info!("New post...");
-        posts::create(&db);
+        posts::create(&db)?;
     } else if arg_matches.subcommand_matches("update").is_some() {
         let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
-            val.value_of("id").unwrap().parse().unwrap()
+            val.value_of("id").unwrap().parse()?
         } else {
             0
         };
         info!("Updating post ...");
-        posts::update_handler(&db, id);
+        posts::update_handler(&db, id)?;
     } else if arg_matches.subcommand_matches("delete").is_some() {
         let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
-            val.value_of("id").unwrap().parse().unwrap()
+            val.value_of("id").unwrap_or_else(|| "0").parse()?
         } else {
             0
         };
         info!("Deleting post");
-        posts::delete_handler(&db, id);
+        posts::delete_handler(&db, id)?;
     }
 
-    posts::display(&db);
+    posts::display(&db)?;
+
+    Ok(())
 }