summary refs log tree commit diff stats
path: root/src/main.rs
blob: 6c384318f825aa7642fe2608f50af593934ecebf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::time;

#[macro_use]
extern crate lazy_static;

mod conf;
mod db;
mod ed;
mod error;
mod logging;
mod posts;
mod user;

fn main() {
    let arg_matches = &*conf::ARGS;
    let start = time::Instant::now();
    logging::checked_init();

    log::info!("clinte starting up!");
    println!("clinte v{}", clap::crate_version!());
    println!("a community notices system");
    println!();

    if *conf::DEBUG {
        log::info!("Startup completed in {:?}ms", start.elapsed().as_millis());
    }

    if arg_matches.subcommand_matches("post").is_some() {
        log::info!("New post...");
        error::helper(posts::create(), "Error creating new post");
    } else if let Some(updmatch) = arg_matches.subcommand_matches("update") {
        let id: usize = if let Some(val) = updmatch.value_of("id") {
            error::helper(val.parse(), "Couldn't parse ID")
        } else {
            0
        };

        log::info!("Updating post ...");

        error::helper(
            posts::update_handler(id),
            format!("Error updating post {}", id).as_ref(),
        );
    } else if let Some(delmatch) = arg_matches.subcommand_matches("delete") {
        let id: usize = if let Some(val) = delmatch.value_of("id") {
            error::helper(val.parse(), "Couldn't parse ID")
        } else {
            0
        };

        log::info!("Deleting post");

        error::helper(
            posts::delete_handler(id),
            format!("Error deleting post {}", id).as_ref(),
        );
    }

    error::helper(posts::display(), "Error displaying posts");
}