2018-10-04 22:47:54 +02:00
|
|
|
use clap::{Arg, ArgMatches, App, SubCommand};
|
|
|
|
|
2018-10-05 13:48:45 +02:00
|
|
|
use std::env;
|
2018-10-04 22:47:54 +02:00
|
|
|
use plume_models::{
|
2018-10-06 13:35:58 +02:00
|
|
|
Connection,
|
2018-10-04 22:47:54 +02:00
|
|
|
instance::*,
|
|
|
|
safe_string::SafeString,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn command<'a, 'b>() -> App<'a, 'b> {
|
|
|
|
SubCommand::with_name("instance")
|
|
|
|
.about("Manage instances")
|
|
|
|
.subcommand(SubCommand::with_name("new")
|
|
|
|
.arg(Arg::with_name("domain")
|
|
|
|
.short("d")
|
2018-10-05 13:48:45 +02:00
|
|
|
.long("domain")
|
|
|
|
.takes_value(true)
|
2018-10-04 22:47:54 +02:00
|
|
|
.help("The domain name of your instance")
|
2018-10-05 13:48:45 +02:00
|
|
|
).arg(Arg::with_name("name")
|
2018-10-04 22:47:54 +02:00
|
|
|
.short("n")
|
2018-10-05 13:48:45 +02:00
|
|
|
.long("name")
|
|
|
|
.takes_value(true)
|
2018-10-04 22:47:54 +02:00
|
|
|
.help("The name of your instance")
|
2018-10-05 13:48:45 +02:00
|
|
|
).arg(Arg::with_name("default-license")
|
2018-10-04 22:47:54 +02:00
|
|
|
.short("l")
|
2018-10-05 13:48:45 +02:00
|
|
|
.long("default-license")
|
|
|
|
.takes_value(true)
|
2018-10-04 22:47:54 +02:00
|
|
|
.help("The license that will be used by default for new articles on this instance")
|
2018-10-05 13:48:45 +02:00
|
|
|
).arg(Arg::with_name("private")
|
2018-10-04 22:47:54 +02:00
|
|
|
.short("p")
|
2018-10-05 13:48:45 +02:00
|
|
|
.long("private")
|
|
|
|
.help("Closes the registrations on this instance")
|
|
|
|
).about("Create a new local instance"))
|
2018-10-04 22:47:54 +02:00
|
|
|
}
|
|
|
|
|
2018-10-06 13:35:58 +02:00
|
|
|
pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
2018-10-04 22:47:54 +02:00
|
|
|
let conn = conn;
|
|
|
|
match args.subcommand() {
|
|
|
|
("new", Some(x)) => new(x, conn),
|
|
|
|
_ => println!("Unknwon subcommand"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-06 13:35:58 +02:00
|
|
|
fn new<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
2018-10-05 13:48:45 +02:00
|
|
|
let domain = args.value_of("domain").map(String::from)
|
|
|
|
.unwrap_or_else(|| env::var("BASE_URL")
|
|
|
|
.unwrap_or_else(|_| super::ask_for("Domain name")));
|
2018-10-04 22:47:54 +02:00
|
|
|
let name = args.value_of("name").map(String::from).unwrap_or_else(|| super::ask_for("Instance name"));
|
2018-11-26 10:21:52 +01:00
|
|
|
let license = args.value_of("default-license").map(String::from).unwrap_or_else(|| String::from("CC-BY-SA"));
|
2018-10-04 22:47:54 +02:00
|
|
|
let open_reg = !args.is_present("private");
|
|
|
|
|
|
|
|
Instance::insert(conn, NewInstance {
|
|
|
|
public_domain: domain,
|
2018-11-26 10:21:52 +01:00
|
|
|
name,
|
2018-10-04 22:47:54 +02:00
|
|
|
local: true,
|
|
|
|
long_description: SafeString::new(""),
|
|
|
|
short_description: SafeString::new(""),
|
|
|
|
default_license: license,
|
|
|
|
open_registrations: open_reg,
|
|
|
|
short_description_html: String::new(),
|
|
|
|
long_description_html: String::new()
|
|
|
|
});
|
|
|
|
}
|