/
main.rs
52 lines (46 loc) · 1.47 KB
/
main.rs
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
extern crate clap;
extern crate diesel;
extern crate dotenv;
extern crate plume_models;
extern crate rpassword;
use clap::App;
use diesel::Connection;
use plume_models::{Connection as Conn, DATABASE_URL};
use std::io::{self, prelude::*};
mod instance;
mod search;
mod users;
fn main() {
let mut app = App::new("Plume CLI")
.bin_name("plm")
.version(env!("CARGO_PKG_VERSION"))
.about("Collection of tools to manage your Plume instance.")
.subcommand(instance::command())
.subcommand(users::command())
.subcommand(search::command());
let matches = app.clone().get_matches();
dotenv::dotenv().ok();
let conn = Conn::establish(DATABASE_URL.as_str());
match matches.subcommand() {
("instance", Some(args)) => {
instance::run(args, &conn.expect("Couldn't connect to the database."))
}
("users", Some(args)) => {
users::run(args, &conn.expect("Couldn't connect to the database."))
}
("search", Some(args)) => {
search::run(args, &conn.expect("Couldn't connect to the database."))
}
_ => app.print_help().expect("Couldn't print help"),
};
}
pub fn ask_for(something: &str) -> String {
print!("{}: ", something);
io::stdout().flush().expect("Couldn't flush STDOUT");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Unable to read line");
input.retain(|c| c != '\n');
input
}