~gbmor/clinte

ref: cf3b6628ce4deb429fad407829b425a7377e2b5d clinte/src/main.rs -rw-r--r-- 1.4 KiB
cf3b6628Ben Morrison hiding some log messages behind -v flag 1 year, 3 months ago
                                                                                
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
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() -> error::Result<()> {
    let arg_matches = &*conf::ARGS;
    let start = time::Instant::now();
    let logfile = format!("/tmp/clinte_{}.log", *user::NAME);
    logging::init(&logfile)?;

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

    let db = db::Conn::new();

    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...");
        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()?
        } else {
            0
        };
        log::info!("Updating post ...");
        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_or_else(|| "0").parse()?
        } else {
            0
        };
        log::info!("Deleting post");
        posts::delete_handler(&db, id)?;
    }

    posts::display(&db)?;

    Ok(())
}