Make sure that -i, -p and -u options take mandatory arguments (#1474)

This commit is contained in:
Avinash Sonawane 2021-05-23 11:57:49 +00:00 committed by GitHub
parent 4140ab7207
commit 70675ff710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View file

@ -58,13 +58,13 @@ pub fn build_cli() -> App<'static, 'static> {
Arg::with_name("interface") Arg::with_name("interface")
.short("i") .short("i")
.long("interface") .long("interface")
.default_value("127.0.0.1") .takes_value(true)
.help("Interface to bind on"), .help("Interface to bind on (default: 127.0.0.1)"),
Arg::with_name("port") Arg::with_name("port")
.short("p") .short("p")
.long("port") .long("port")
.default_value("1111") .takes_value(true)
.help("Which port to use"), .help("Which port to use (default: 1111)"),
Arg::with_name("output_dir") Arg::with_name("output_dir")
.short("o") .short("o")
.long("output-dir") .long("output-dir")
@ -73,9 +73,8 @@ pub fn build_cli() -> App<'static, 'static> {
Arg::with_name("base_url") Arg::with_name("base_url")
.short("u") .short("u")
.long("base-url") .long("base-url")
.default_value("127.0.0.1")
.takes_value(true) .takes_value(true)
.help("Changes the base_url"), .help("Changes the base_url (default: 127.0.0.1)"),
Arg::with_name("drafts") Arg::with_name("drafts")
.long("drafts") .long("drafts")
.takes_value(false) .takes_value(false)

View file

@ -54,7 +54,7 @@ fn main() {
} }
("serve", Some(matches)) => { ("serve", Some(matches)) => {
let interface = matches.value_of("interface").unwrap_or("127.0.0.1"); let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
let mut port: u16 = match matches.value_of("port").unwrap().parse() { let mut port: u16 = match matches.value_of("port").unwrap_or("1111").parse() {
Ok(x) => x, Ok(x) => x,
Err(_) => { Err(_) => {
console::error("The request port needs to be an integer"); console::error("The request port needs to be an integer");
@ -80,7 +80,7 @@ fn main() {
} }
} }
let output_dir = matches.value_of("output_dir").map(|output_dir| Path::new(output_dir)); let output_dir = matches.value_of("output_dir").map(|output_dir| Path::new(output_dir));
let base_url = matches.value_of("base_url").unwrap(); let base_url = matches.value_of("base_url").unwrap_or("127.0.0.1");
console::info("Building site..."); console::info("Building site...");
match cmd::serve( match cmd::serve(
&root_dir, &root_dir,