~gbmor/clinte

99c5537622344ecba5a4c7d23a9bc227d9bd7fe3 — Ben Morrison 1 year, 2 months ago 896f987
post ID can be specified as an argument. if absent, user will be prompted
3 files changed, 27 insertions(+), 15 deletions(-)

M src/conf.rs
M src/main.rs
M src/posts.rs
M src/conf.rs => src/conf.rs +20 -2
@@ 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()
}

M src/main.rs => src/main.rs +6 -12
@@ 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
        };

M src/posts.rs => src/posts.rs +1 -1
@@ 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(())
}