refac(cli): implement path builder...
... instead mutated path buf
This commit is contained in:
parent
95e41a7b8d
commit
4803357a6b
1 changed files with 6 additions and 8 deletions
|
@ -5,7 +5,7 @@ mod opts;
|
|||
|
||||
use config::Config;
|
||||
use opts::{StructOpt, AppOpt, ApplyOpt};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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 file_name = Path::new(&file_name);
|
||||
let mut filepath = PathBuf::from(&config.directory);
|
||||
filepath.push(file_name);
|
||||
if file_name.extension().is_none() {
|
||||
filepath.set_extension("sql");
|
||||
}
|
||||
let file_path = migra_core::path::PathBuilder::new(config.directory)
|
||||
.append(file_name)
|
||||
.default_extension("sql")
|
||||
.build();
|
||||
|
||||
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) {
|
||||
Ok(_) => {
|
||||
|
|
Reference in a new issue