fix loading style
This commit is contained in:
parent
3bc71acd79
commit
28adf2ca85
1 changed files with 6 additions and 5 deletions
|
|
@ -347,7 +347,7 @@ impl Config {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn style(&self) -> Option<String> {
|
pub fn style(&self) -> Option<String> {
|
||||||
style_path(None)
|
style_path(self.style.as_ref())
|
||||||
.ok()
|
.ok()
|
||||||
.map(|pb| pb.display().to_string())
|
.map(|pb| pb.display().to_string())
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
|
|
@ -599,7 +599,7 @@ pub fn parse_args() -> Config {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Will return Err when it cannot resolve any path or no style is found
|
/// Will return Err when it cannot resolve any path or no style is found
|
||||||
fn style_path(full_path: Option<String>) -> Result<PathBuf, Error> {
|
fn style_path(full_path: Option<&String>) -> Result<PathBuf, Error> {
|
||||||
let alternative_paths = path_alternatives(
|
let alternative_paths = path_alternatives(
|
||||||
vec![dirs::config_dir()],
|
vec![dirs::config_dir()],
|
||||||
&PathBuf::from("worf").join("style.css"),
|
&PathBuf::from("worf").join("style.css"),
|
||||||
|
|
@ -610,7 +610,7 @@ fn style_path(full_path: Option<String>) -> Result<PathBuf, Error> {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Will return Err when it cannot resolve any path or no style is found
|
/// Will return Err when it cannot resolve any path or no style is found
|
||||||
pub fn conf_path(full_path: Option<String>) -> Result<PathBuf, Error> {
|
pub fn conf_path(full_path: Option<&String>) -> Result<PathBuf, Error> {
|
||||||
let alternative_paths = path_alternatives(
|
let alternative_paths = path_alternatives(
|
||||||
vec![dirs::config_dir()],
|
vec![dirs::config_dir()],
|
||||||
&PathBuf::from("worf").join("config"),
|
&PathBuf::from("worf").join("config"),
|
||||||
|
|
@ -633,9 +633,10 @@ pub fn path_alternatives(base_paths: Vec<Option<PathBuf>>, sub_path: &PathBuf) -
|
||||||
///
|
///
|
||||||
/// Will return `Err` if it is not able to find any valid path
|
/// Will return `Err` if it is not able to find any valid path
|
||||||
pub fn resolve_path(
|
pub fn resolve_path(
|
||||||
full_path: Option<String>,
|
full_path: Option<&String>,
|
||||||
alternatives: Vec<PathBuf>,
|
alternatives: Vec<PathBuf>,
|
||||||
) -> Result<PathBuf, Error> {
|
) -> Result<PathBuf, Error> {
|
||||||
|
log::debug!("resolving path for {full_path:?}, with alternatives: {alternatives:?}");
|
||||||
full_path
|
full_path
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.and_then(|p| p.canonicalize().ok().filter(|c| c.exists()))
|
.and_then(|p| p.canonicalize().ok().filter(|c| c.exists()))
|
||||||
|
|
@ -656,7 +657,7 @@ pub fn resolve_path(
|
||||||
/// * no config file exists
|
/// * no config file exists
|
||||||
/// * config file and args cannot be merged
|
/// * config file and args cannot be merged
|
||||||
pub fn load_config(args_opt: Option<&Config>) -> Result<Config, Error> {
|
pub fn load_config(args_opt: Option<&Config>) -> Result<Config, Error> {
|
||||||
let config_path = conf_path(args_opt.as_ref().and_then(|c| c.config.clone()));
|
let config_path = conf_path(args_opt.as_ref().and_then(|c| c.config.as_ref()));
|
||||||
match config_path {
|
match config_path {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
let toml_content = fs::read_to_string(path).map_err(|e| Error::Io(format!("{e}")))?;
|
let toml_content = fs::read_to_string(path).map_err(|e| Error::Io(format!("{e}")))?;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue