From 4803357a6b2d9b306bfa8db51f0bf021f43209f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 31 Jan 2021 14:54:50 +0300 Subject: [PATCH] refac(cli): implement path builder... ... instead mutated path buf --- migra-cli/src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/migra-cli/src/main.rs b/migra-cli/src/main.rs index 4b0da55..25a7c8e 100644 --- a/migra-cli/src/main.rs +++ b/migra-cli/src/main.rs @@ -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> { let opt = AppOpt::from_args(); @@ -19,14 +19,12 @@ fn main() -> Result<(), Box> { 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(_) => {