summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/conf.rs22
-rw-r--r--src/main.rs18
-rw-r--r--src/posts.rs2
3 files changed, 27 insertions, 15 deletions
diff --git a/src/conf.rs b/src/conf.rs
index dd3b298..2a26a92 100644
--- a/src/conf.rs
+++ b/src/conf.rs
@@ -17,7 +17,25 @@ fn get_config() -> clap::ArgMatches<'static> {
                 .help("Verbose logging"),
         )
         .subcommand(clap::SubCommand::with_name("post").about("Post a new notice"))
-        .subcommand(clap::SubCommand::with_name("update").about("Update a notice you've posted"))
-        .subcommand(clap::SubCommand::with_name("delete").about("Delete a notice you've posted"))
+        .subcommand(
+            clap::SubCommand::with_name("update")
+                .about("Update a notice you've posted")
+                .arg(
+                    Arg::with_name("id")
+                        .help("Numeric ID of the post to update")
+                        .value_name("ID")
+                        .takes_value(true),
+                ),
+        )
+        .subcommand(
+            clap::SubCommand::with_name("delete")
+                .about("Delete a notice you've posted")
+                .arg(
+                    Arg::with_name("id")
+                        .help("Numeric ID of the post to delete")
+                        .value_name("ID")
+                        .takes_value(true),
+                ),
+        )
         .get_matches()
 }
diff --git a/src/main.rs b/src/main.rs
index 06fb4ca..f6d136d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,12 +30,9 @@ fn main() {
     if arg_matches.subcommand_matches("post").is_some() {
         log::info!("New post...");
         error::helper(posts::create(&db), "Error creating new post");
-    } else if arg_matches.subcommand_matches("update").is_some() {
-        let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
-            error::helper(
-                val.value_of("id").unwrap_or_else(|| "0").parse(),
-                "Couldn't parse ID",
-            )
+    } else if let Some(updmatch) = arg_matches.subcommand_matches("update") {
+        let id: u32 = if let Some(val) = updmatch.value_of("id") {
+            error::helper(val.parse(), "Couldn't parse ID")
         } else {
             0
         };
@@ -46,12 +43,9 @@ fn main() {
             posts::update_handler(&db, id),
             format!("Error updating post {}", id).as_ref(),
         );
-    } else if arg_matches.subcommand_matches("delete").is_some() {
-        let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
-            error::helper(
-                val.value_of("id").unwrap_or_else(|| "0").parse(),
-                "Couldn't parse ID",
-            )
+    } else if let Some(delmatch) = arg_matches.subcommand_matches("delete") {
+        let id: u32 = if let Some(val) = delmatch.value_of("id") {
+            error::helper(val.parse(), "Couldn't parse ID")
         } else {
             0
         };
diff --git a/src/posts.rs b/src/posts.rs
index 76a5187..781ad9d 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -186,6 +186,7 @@ pub fn delete_handler(db: &db::Conn, id: u32) -> error::Result<()> {
         println!("ID of the post to delete?");
         let mut id_num_in = String::new();
         io::stdin().read_line(&mut id_num_in)?;
+        println!();
         id_num_in.trim().parse()?
     } else {
         id
@@ -207,7 +208,6 @@ pub fn delete_handler(db: &db::Conn, id: u32) -> error::Result<()> {
     }
 
     exec_stmt_no_params(&mut del_stmt)?;
-    println!();
     Ok(())
 }