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]
|
||||
name = "plume-cli"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Bat' <baptiste@gelez.xyz>"]
|
||||
|
||||
[[bin]]
|
||||
name = "plm"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = "2.32"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use clap::{Arg, ArgMatches, App, SubCommand};
|
||||
use diesel::PgConnection;
|
||||
|
||||
use std::env;
|
||||
use plume_models::{
|
||||
instance::*,
|
||||
safe_string::SafeString,
|
||||
|
@ -12,20 +13,24 @@ pub fn command<'a, 'b>() -> App<'a, 'b> {
|
|||
.subcommand(SubCommand::with_name("new")
|
||||
.arg(Arg::with_name("domain")
|
||||
.short("d")
|
||||
.takes_value(true))
|
||||
.long("domain")
|
||||
.takes_value(true)
|
||||
.help("The domain name of your instance")
|
||||
.arg(Arg::with_name("name")
|
||||
).arg(Arg::with_name("name")
|
||||
.short("n")
|
||||
.takes_value(true))
|
||||
.long("name")
|
||||
.takes_value(true)
|
||||
.help("The name of your instance")
|
||||
.arg(Arg::with_name("default-license")
|
||||
).arg(Arg::with_name("default-license")
|
||||
.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")
|
||||
.arg(Arg::with_name("private")
|
||||
).arg(Arg::with_name("private")
|
||||
.short("p")
|
||||
.help("Closes the registrations on this instance"))
|
||||
.help("Create a new local instance"))
|
||||
.long("private")
|
||||
.help("Closes the registrations on this instance")
|
||||
).about("Create a new local instance"))
|
||||
}
|
||||
|
||||
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) {
|
||||
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 license = args.value_of("default-license").map(String::from).unwrap_or(String::from("CC-0"));
|
||||
let open_reg = !args.is_present("private");
|
||||
|
|
|
@ -5,7 +5,7 @@ extern crate plume_models;
|
|||
|
||||
use clap::App;
|
||||
use diesel::{Connection, PgConnection};
|
||||
use std::io::{self, Write};
|
||||
use std::io::{self, prelude::*};
|
||||
use plume_models::DB_URL;
|
||||
|
||||
mod instance;
|
||||
|
@ -28,8 +28,8 @@ fn main() {
|
|||
}
|
||||
|
||||
pub fn ask_for(something: &str) -> String {
|
||||
write!(io::stdout(), "{}", something).ok();
|
||||
write!(io::stdout(), ": ").ok();
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue