refactor
This commit is contained in:
parent
3806262531
commit
d628550abc
1 changed files with 6 additions and 10 deletions
|
@ -1,15 +1,16 @@
|
|||
//! `config update v1` subcommand
|
||||
//! <https://firefish.dev/firefish/firefish/-/issues/10947>
|
||||
|
||||
use crate::config::{
|
||||
client, server, Revision, CLIENT_CONFIG_PATH, OLD_CONFIG_PATH, SERVER_CONFIG_PATH,
|
||||
use crate::{
|
||||
command::config::{read_file_as_string, ReadError},
|
||||
config::{client, server, Revision, CLIENT_CONFIG_PATH, OLD_CONFIG_PATH, SERVER_CONFIG_PATH},
|
||||
};
|
||||
use color_print::cprintln;
|
||||
use sqlx::{postgres::PgConnectOptions, ConnectOptions};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
io::{self, Read, Write},
|
||||
io::{self, Write},
|
||||
path::Path,
|
||||
};
|
||||
use url::Url;
|
||||
|
@ -34,7 +35,7 @@ pub(crate) enum Error {
|
|||
#[derive(thiserror::Error, Debug)]
|
||||
pub(crate) enum ReadYamlConfigError {
|
||||
#[error(transparent)]
|
||||
ReadFile(#[from] io::Error),
|
||||
ReadFile(#[from] ReadError),
|
||||
#[error(transparent)]
|
||||
Yaml(#[from] yaml_rust::ScanError),
|
||||
#[error("invalid config ({0})")]
|
||||
|
@ -57,12 +58,7 @@ pub(crate) enum WriteTomlConfigError {
|
|||
}
|
||||
|
||||
fn read_default_yml() -> Result<HashMap<String, Yaml>, ReadYamlConfigError> {
|
||||
let mut default_yml = fs::File::open(OLD_CONFIG_PATH)?;
|
||||
|
||||
let mut buffer = String::new();
|
||||
default_yml.read_to_string(&mut buffer)?;
|
||||
|
||||
let content = YamlLoader::load_from_str(&buffer)?;
|
||||
let content = YamlLoader::load_from_str(&read_file_as_string(OLD_CONFIG_PATH)?)?;
|
||||
|
||||
if content.is_empty() {
|
||||
return Err(ReadYamlConfigError::InvalidConfig(
|
||||
|
|
Loading…
Reference in a new issue