Simplify command line argument verification code
This commit is contained in:
parent
65d91b122e
commit
cdf244f0f5
1 changed files with 46 additions and 61 deletions
|
@ -28,84 +28,69 @@ We would love it if you could star the repository (https://github.com/surrealdb/
|
||||||
";
|
";
|
||||||
|
|
||||||
fn file_valid(v: &str) -> Result<(), String> {
|
fn file_valid(v: &str) -> Result<(), String> {
|
||||||
if !v.is_empty() {
|
match v {
|
||||||
return Ok(());
|
v if !v.is_empty() => Ok(()),
|
||||||
}
|
_ => Err(String::from(
|
||||||
Err(String::from(
|
|
||||||
"\
|
"\
|
||||||
Provide a valid path to a SQL file\
|
Provide a valid path to a SQL file\
|
||||||
",
|
",
|
||||||
))
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_valid(v: &str) -> Result<(), String> {
|
fn path_valid(v: &str) -> Result<(), String> {
|
||||||
if v == "memory" {
|
match v {
|
||||||
return Ok(());
|
"memory" => Ok(()),
|
||||||
}
|
v if v.starts_with("file:") => Ok(()),
|
||||||
if v.starts_with("file:") {
|
v if v.starts_with("rocksdb:") => Ok(()),
|
||||||
return Ok(());
|
v if v.starts_with("tikv:") => Ok(()),
|
||||||
}
|
v if v.starts_with("fdb:") => Ok(()),
|
||||||
if v.starts_with("tikv:") {
|
_ => Err(String::from(
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
if v.starts_with("fdb:") {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Err(String::from(
|
|
||||||
"\
|
"\
|
||||||
Provide a valid database path parameter\
|
Provide a valid database path parameter\
|
||||||
",
|
",
|
||||||
))
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn conn_valid(v: &str) -> Result<(), String> {
|
fn conn_valid(v: &str) -> Result<(), String> {
|
||||||
if v.starts_with("https://") {
|
match v {
|
||||||
return Ok(());
|
v if v.starts_with("http://") => Ok(()),
|
||||||
}
|
v if v.starts_with("https://") => Ok(()),
|
||||||
if v.starts_with("http://") {
|
_ => Err(String::from(
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Err(String::from(
|
|
||||||
"\
|
"\
|
||||||
Provide a valid database connection string\
|
Provide a valid database connection string\
|
||||||
",
|
",
|
||||||
))
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_valid(v: &str) -> Result<(), String> {
|
fn from_valid(v: &str) -> Result<(), String> {
|
||||||
if v.starts_with("https://") {
|
match v {
|
||||||
return Ok(());
|
v if v.ends_with(".db") => Ok(()),
|
||||||
}
|
v if v.starts_with("http://") => Ok(()),
|
||||||
if v.starts_with("http://") {
|
v if v.starts_with("https://") => Ok(()),
|
||||||
return Ok(());
|
_ => Err(String::from(
|
||||||
}
|
|
||||||
if v.ends_with(".db") {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Err(String::from(
|
|
||||||
"\
|
"\
|
||||||
Provide a valid database connection string, \
|
Provide a valid database connection string, \
|
||||||
or specify the path to a database file\
|
or specify the path to a database file\
|
||||||
",
|
",
|
||||||
))
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_valid(v: &str) -> Result<(), String> {
|
fn into_valid(v: &str) -> Result<(), String> {
|
||||||
if v.starts_with("https://") {
|
match v {
|
||||||
return Ok(());
|
v if v.ends_with(".db") => Ok(()),
|
||||||
}
|
v if v.starts_with("http://") => Ok(()),
|
||||||
if v.starts_with("http://") {
|
v if v.starts_with("https://") => Ok(()),
|
||||||
return Ok(());
|
_ => Err(String::from(
|
||||||
}
|
|
||||||
if v.ends_with(".db") {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Err(String::from(
|
|
||||||
"\
|
"\
|
||||||
Provide a valid database connection string, \
|
Provide a valid database connection string, \
|
||||||
or specify the path to a database file\
|
or specify the path to a database file\
|
||||||
",
|
",
|
||||||
))
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_valid(v: &str) -> Result<(), String> {
|
fn key_valid(v: &str) -> Result<(), String> {
|
||||||
|
|
Loading…
Reference in a new issue