From 99c5537622344ecba5a4c7d23a9bc227d9bd7fe3 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Tue, 26 May 2020 23:47:52 -0400 Subject: post ID can be specified as an argument. if absent, user will be prompted --- src/main.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/main.rs') 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 }; -- cgit 1.4.1-2-gfad0