Verify database path parameter on command-line

This commit is contained in:
Tobie Morgan Hitchcock 2022-01-13 06:56:24 +00:00
parent 53a4f76516
commit 643344151b

View file

@ -30,6 +30,23 @@ fn file_valid(v: String) -> Result<(), String> {
))
}
fn path_valid(v: String) -> Result<(), String> {
if v == "memory" {
return Ok(());
}
if v.starts_with("file://") {
return Ok(());
}
if v.starts_with("tikv://") {
return Ok(());
}
Err(String::from(
"\
Provide a valid database path paramater\
",
))
}
fn conn_valid(v: String) -> Result<(), String> {
if v.starts_with("https://") {
return Ok(());
@ -116,6 +133,7 @@ pub fn init() {
Arg::with_name("path")
.index(1)
.required(true)
.validator(path_valid)
.default_value("memory")
.help("Database path used for storing data"),
)