From e2b3166bb56ade4d66c2822db81ed49087fc3813 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:17:46 -0600 Subject: [PATCH] read system and local config settings Fixes #1426 Fixes #1425 --- man/man1/mise.1 | 4 ++-- src/config/settings.rs | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/man/man1/mise.1 b/man/man1/mise.1 index a249331538..7b1e583613 100644 --- a/man/man1/mise.1 +++ b/man/man1/mise.1 @@ -1,6 +1,6 @@ .ie \n(.g .ds Aq \(aq .el .ds Aq ' -.TH mise 1 "mise 2024.1.27" +.TH mise 1 "mise 2024.1.28" .SH NAME mise \- The front\-end to your dev env .SH SYNOPSIS @@ -179,6 +179,6 @@ Examples: $ mise settings Show settings in use $ mise settings set color 0 Disable color by modifying global config file .SH VERSION -v2024.1.27 +v2024.1.28 .SH AUTHORS Jeff Dickey <@jdx> diff --git a/src/config/settings.rs b/src/config/settings.rs index 0edd973053..f8e379311e 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -1,5 +1,6 @@ use std::collections::{BTreeSet, HashSet}; use std::fmt::{Debug, Display, Formatter}; +use std::iter::once; use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; @@ -11,7 +12,8 @@ use once_cell::sync::Lazy; use serde::ser::Error; use serde_derive::{Deserialize, Serialize}; -use crate::{dirs, env, file}; +use crate::config::{system_config_files, DEFAULT_CONFIG_FILENAMES}; +use crate::{config, dirs, env, file}; #[derive(Config, Default, Debug, Clone, Serialize)] #[config(partial_attr(derive(Clone, Serialize, Default)))] @@ -257,9 +259,7 @@ impl Settings { { return Ok(Default::default()); } - let raw = file::read_to_string(global_config)?; - let settings_file: SettingsFile = toml::from_str(&raw)?; - Ok(settings_file.settings) + Self::parse_settings_file(global_config) } fn deprecated_settings_file() -> Result { @@ -271,9 +271,24 @@ impl Settings { Self::from_file(settings_file) } + fn parse_settings_file(path: &PathBuf) -> Result { + let raw = file::read_to_string(path)?; + let settings_file: SettingsFile = toml::from_str(&raw)?; + Ok(settings_file.settings) + } + fn all_settings_files() -> Vec { - vec![Self::config_settings(), Self::deprecated_settings_file()] - .into_iter() + config::load_config_paths(&DEFAULT_CONFIG_FILENAMES) + .iter() + .filter(|p| { + let filename = p.file_name().unwrap_or_default().to_string_lossy(); + filename != *env::MISE_DEFAULT_TOOL_VERSIONS_FILENAME + && filename != ".tool-versions" + }) + .map(Self::parse_settings_file) + .chain(once(Self::config_settings())) + .chain(once(Self::deprecated_settings_file())) + .chain(system_config_files().iter().map(Self::parse_settings_file)) .filter_map(|cfg| match cfg { Ok(cfg) => Some(cfg), Err(e) => {