From ee4d137a7d399c8cda645a72fd8b8c5cdd05cccd Mon Sep 17 00:00:00 2001 From: EETagent Date: Sun, 30 Oct 2022 12:52:09 +0100 Subject: [PATCH] refactor: require URL instead --- recovery/src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/recovery/src/main.rs b/recovery/src/main.rs index aa831b5..1d49a5d 100644 --- a/recovery/src/main.rs +++ b/recovery/src/main.rs @@ -11,13 +11,13 @@ use ::entity::parent::Entity as Parent; #[tokio::main] async fn main() -> Result<(), Box> { let clap = command!() - .arg(arg!([name] "Path to the db .sql backup")) .arg( arg!( - -d --database "Path to the database SQL backup file" + -d --database "URL to the database or sql file with postgres:// or sqlite://" ) + .alias("url") .required(true) - .value_parser(value_parser!(PathBuf)), + .value_parser(value_parser!(Url)), ) .arg( arg!( @@ -34,8 +34,13 @@ async fn main() -> Result<(), Box> { ) .get_matches(); - let mut sqlite_url = Url::from_file_path(clap.get_one::("DATABASE").unwrap()).unwrap(); - sqlite_url.set_scheme("sqlite").unwrap(); + let sqlite_url = clap.get_one::("database").unwrap(); + + println!("Connecting to {:?}", sqlite_url); + + if sqlite_url.scheme() != "sqlite" && sqlite_url.scheme() != "postgres" { + return Err("URL scheme postgres:// or sqlite:// required")?; + } let db: DatabaseConnection = Database::connect(sqlite_url.as_str()).await?;