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

View File

@ -54,7 +54,7 @@ fn main() {
}
("serve", Some(matches)) => {
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,
Err(_) => {
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 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...");
match cmd::serve(
&root_dir,