blob: 35df02f7a71a27a79272d824e0ef628fe285c3d3 (
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
61
62
63
|
use std::time;
#[macro_use]
extern crate lazy_static;
use clap;
use log::info;
mod db;
mod ed;
mod error;
mod logging;
mod posts;
mod user;
fn main() {
let arg_matches = clap::App::new("clinte")
.version(clap::crate_version!())
.author("Ben Morrison (gbmor)")
.about("Command-line community notices system")
.subcommand(clap::SubCommand::with_name("post").about("Post a new notice"))
.subcommand(
clap::SubCommand::with_name("update_handler").about("Update a notice you've posted"),
)
.subcommand(
clap::SubCommand::with_name("delete_handler").about("Delete a notice you've posted"),
)
.get_matches();
let start = time::Instant::now();
logging::init();
info!("clinte starting up!");
println!("clinte v{}", clap::crate_version!());
println!("a community notices system");
println!();
let db = db::Conn::new();
info!("Startup completed in {:?}ms", start.elapsed().as_millis());
if arg_matches.subcommand_matches("post").is_some() {
info!("New post...");
posts::create(&db);
} else if arg_matches.subcommand_matches("update_handler").is_some() {
let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
val.value_of("id").unwrap().parse().unwrap()
} else {
0
};
info!("Updating post ...");
posts::update_handler(&db, id);
} else if arg_matches.subcommand_matches("delete_handler").is_some() {
let id: u32 = if let Some(val) = arg_matches.subcommand_matches("update_handler") {
val.value_of("id").unwrap().parse().unwrap()
} else {
0
};
info!("Deleting post");
posts::delete_handler(&db, id);
}
posts::display(&db);
}
|