Improve the plm instance new command
Add long arguments Fix the help messages Actually write to StdOut when needed Fallback to BASE_URL first if domain is not specified
This commit is contained in:
parent
6723432e52
commit
0da5d2e927
|
@ -1,10 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "plume-cli"
|
name = "plume-cli"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Bat' <baptiste@gelez.xyz>"]
|
authors = ["Bat' <baptiste@gelez.xyz>"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "plm"
|
name = "plm"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.32"
|
clap = "2.32"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use clap::{Arg, ArgMatches, App, SubCommand};
|
use clap::{Arg, ArgMatches, App, SubCommand};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
instance::*,
|
instance::*,
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
|
@ -12,20 +13,24 @@ pub fn command<'a, 'b>() -> App<'a, 'b> {
|
||||||
.subcommand(SubCommand::with_name("new")
|
.subcommand(SubCommand::with_name("new")
|
||||||
.arg(Arg::with_name("domain")
|
.arg(Arg::with_name("domain")
|
||||||
.short("d")
|
.short("d")
|
||||||
.takes_value(true))
|
.long("domain")
|
||||||
|
.takes_value(true)
|
||||||
.help("The domain name of your instance")
|
.help("The domain name of your instance")
|
||||||
.arg(Arg::with_name("name")
|
).arg(Arg::with_name("name")
|
||||||
.short("n")
|
.short("n")
|
||||||
.takes_value(true))
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
.help("The name of your instance")
|
.help("The name of your instance")
|
||||||
.arg(Arg::with_name("default-license")
|
).arg(Arg::with_name("default-license")
|
||||||
.short("l")
|
.short("l")
|
||||||
.takes_value(true))
|
.long("default-license")
|
||||||
|
.takes_value(true)
|
||||||
.help("The license that will be used by default for new articles on this instance")
|
.help("The license that will be used by default for new articles on this instance")
|
||||||
.arg(Arg::with_name("private")
|
).arg(Arg::with_name("private")
|
||||||
.short("p")
|
.short("p")
|
||||||
.help("Closes the registrations on this instance"))
|
.long("private")
|
||||||
.help("Create a new local instance"))
|
.help("Closes the registrations on this instance")
|
||||||
|
).about("Create a new local instance"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) {
|
pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) {
|
||||||
|
@ -37,7 +42,9 @@ pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new<'a>(args: &ArgMatches<'a>, conn: &PgConnection) {
|
fn new<'a>(args: &ArgMatches<'a>, conn: &PgConnection) {
|
||||||
let domain = args.value_of("domain").map(String::from).unwrap_or_else(|| super::ask_for("Domain name"));
|
let domain = args.value_of("domain").map(String::from)
|
||||||
|
.unwrap_or_else(|| env::var("BASE_URL")
|
||||||
|
.unwrap_or_else(|_| super::ask_for("Domain name")));
|
||||||
let name = args.value_of("name").map(String::from).unwrap_or_else(|| super::ask_for("Instance name"));
|
let name = args.value_of("name").map(String::from).unwrap_or_else(|| super::ask_for("Instance name"));
|
||||||
let license = args.value_of("default-license").map(String::from).unwrap_or(String::from("CC-0"));
|
let license = args.value_of("default-license").map(String::from).unwrap_or(String::from("CC-0"));
|
||||||
let open_reg = !args.is_present("private");
|
let open_reg = !args.is_present("private");
|
||||||
|
|
|
@ -5,7 +5,7 @@ extern crate plume_models;
|
||||||
|
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use diesel::{Connection, PgConnection};
|
use diesel::{Connection, PgConnection};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, prelude::*};
|
||||||
use plume_models::DB_URL;
|
use plume_models::DB_URL;
|
||||||
|
|
||||||
mod instance;
|
mod instance;
|
||||||
|
@ -28,8 +28,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ask_for(something: &str) -> String {
|
pub fn ask_for(something: &str) -> String {
|
||||||
write!(io::stdout(), "{}", something).ok();
|
print!("{}: ", something);
|
||||||
write!(io::stdout(), ": ").ok();
|
io::stdout().flush().expect("Couldn't flush STDOUT");
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input).expect("Unable to read line");
|
io::stdin().read_line(&mut input).expect("Unable to read line");
|
||||||
input.retain(|c| c != '\n');
|
input.retain(|c| c != '\n');
|
||||||
|
|
Loading…
Reference in New Issue