Archived
1
0
Fork 0

refac(cli): implement path builder...

... instead mutated path buf
This commit is contained in:
Dmitriy Pleshevskiy 2021-01-31 14:54:50 +03:00
parent 95e41a7b8d
commit 4803357a6b

View file

@ -5,7 +5,7 @@ mod opts;
use config::Config; use config::Config;
use opts::{StructOpt, AppOpt, ApplyOpt}; use opts::{StructOpt, AppOpt, ApplyOpt};
use std::path::{Path, PathBuf}; use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let opt = AppOpt::from_args(); let opt = AppOpt::from_args();
@ -19,14 +19,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = migra_core::database::connect(&config.database.connection)?; let mut client = migra_core::database::connect(&config.database.connection)?;
let file_name = Path::new(&file_name); let file_path = migra_core::path::PathBuilder::new(config.directory)
let mut filepath = PathBuf::from(&config.directory); .append(file_name)
filepath.push(file_name); .default_extension("sql")
if file_name.extension().is_none() { .build();
filepath.set_extension("sql");
}
let content = std::fs::read_to_string(filepath)?; let content = fs::read_to_string(file_path)?;
match migra_core::database::apply_sql(&mut client, &content) { match migra_core::database::apply_sql(&mut client, &content) {
Ok(_) => { Ok(_) => {