2018-10-04 20:47:54 +00:00
|
|
|
extern crate clap;
|
|
|
|
extern crate diesel;
|
|
|
|
extern crate dotenv;
|
|
|
|
extern crate plume_models;
|
2018-10-05 12:09:04 +00:00
|
|
|
extern crate rpassword;
|
2018-10-04 20:47:54 +00:00
|
|
|
|
|
|
|
use clap::App;
|
2018-10-06 11:35:58 +00:00
|
|
|
use diesel::Connection;
|
2018-10-05 11:48:45 +00:00
|
|
|
use std::io::{self, prelude::*};
|
2018-10-06 18:17:36 +00:00
|
|
|
use plume_models::{DATABASE_URL, Connection as Conn};
|
2018-10-04 20:47:54 +00:00
|
|
|
|
|
|
|
mod instance;
|
2018-10-05 12:09:04 +00:00
|
|
|
mod users;
|
2018-10-04 20:47:54 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut app = App::new("Plume CLI")
|
|
|
|
.bin_name("plm")
|
2018-10-06 17:33:10 +00:00
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
2018-10-04 20:47:54 +00:00
|
|
|
.about("Collection of tools to manage your Plume instance.")
|
2018-10-05 12:09:04 +00:00
|
|
|
.subcommand(instance::command())
|
|
|
|
.subcommand(users::command());
|
2018-10-04 20:47:54 +00:00
|
|
|
let matches = app.clone().get_matches();
|
|
|
|
|
|
|
|
dotenv::dotenv().ok();
|
2018-10-06 18:17:36 +00:00
|
|
|
let conn = Conn::establish(DATABASE_URL.as_str());
|
2018-10-04 20:47:54 +00:00
|
|
|
|
|
|
|
match matches.subcommand() {
|
|
|
|
("instance", Some(args)) => instance::run(args, &conn.expect("Couldn't connect to the database.")),
|
2018-10-05 12:09:04 +00:00
|
|
|
("users", Some(args)) => users::run(args, &conn.expect("Couldn't connect to the database.")),
|
2018-10-04 20:47:54 +00:00
|
|
|
_ => app.print_help().unwrap()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ask_for(something: &str) -> String {
|
2018-10-05 11:48:45 +00:00
|
|
|
print!("{}: ", something);
|
|
|
|
io::stdout().flush().expect("Couldn't flush STDOUT");
|
2018-10-04 20:47:54 +00:00
|
|
|
let mut input = String::new();
|
|
|
|
io::stdin().read_line(&mut input).expect("Unable to read line");
|
|
|
|
input.retain(|c| c != '\n');
|
|
|
|
input
|
|
|
|
}
|