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