Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Remove cli settings migration (#723)

Aleksandr Golokoz4206d5cb4feb
diff --git a/crates/cli/src/interactive/components/application.rs b/crates/cli/src/interactive/components/application.rs
index d4f12fbd3..71351a493 100644
--- a/crates/cli/src/interactive/components/application.rs
+++ b/crates/cli/src/interactive/components/application.rs
@@ -51,7 +51,7 @@ pub struct ApplicationState {
impl ApplicationState {
pub fn load_preferences() -> Result<Preferences, Box<dyn std::error::Error>> {
- Preferences::load_or_migrate(&Self::settings_file_path("config")?, &Self::settings_file_path("settings")?)
+ Preferences::load(&Self::settings_file_path("config")?)
}
pub fn session_state(&self) -> Option<&dyn SessionState> {
diff --git a/crates/cli/src/interactive/components/preferences.rs b/crates/cli/src/interactive/components/preferences.rs
index ce14935de..0452c4a34 100644
--- a/crates/cli/src/interactive/components/preferences.rs
+++ b/crates/cli/src/interactive/components/preferences.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, error::Error, fs, io, path::Path};
+use std::{fs, io, path::Path};
use serde::{Deserialize, Serialize};
@@ -17,49 +17,15 @@ pub struct Preferences {
}
impl Preferences {
- pub(super) fn load_or_migrate(
- config_path: &Path,
- legacy_path: &Path,
- ) -> Result<Self, Box<dyn Error>> {
- if !legacy_path.exists() {
- return if config_path.exists() {
- Self::load(config_path)
- } else {
- Ok(Self::default())
- };
- }
-
- let mut preferences = if config_path.exists() {
- Self::load(config_path)?
- } else {
- Self::default()
- };
-
- let mut legacy: HashMap<String, HashMap<String, String>> = toml::from_str(&fs::read_to_string(legacy_path)?)?;
- let settings = legacy.remove("settings").unwrap_or_default();
- if let Some(raw) = settings.get("cli_preferences")
- && let Ok(legacy_preferences) = serde_json::from_str::<Self>(raw)
- {
- preferences.thinking = legacy_preferences.thinking;
- preferences.sampling = legacy_preferences.sampling;
- }
- if let Some(raw) = settings.get("app") {
- let app_settings: Self = serde_json::from_str(raw)?;
- preferences.selected_model_id = app_settings.selected_model_id;
- }
- if let Some(name) = settings.get("theme") {
- preferences.theme = Theme::from_name(name)
- .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, format!("unknown legacy theme: {name}")))?;
- }
-
- preferences.store(config_path)?;
- Ok(preferences)
+ pub(super) fn load(path: &Path) -> Result<Self, Box<dyn std::error::Error>> {
+ let contents = fs::read_to_string(path)?;
+ Ok(toml::from_str(&contents)?)
}
pub(super) fn store(
&self,
path: &Path,
- ) -> Result<(), Box<dyn Error>> {
+ ) -> Result<(), Box<dyn std::error::Error>> {
let parent = path
.parent()
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "settings file has no parent directory"))?;
@@ -67,9 +33,4 @@ impl Preferences {
fs::write(path, toml::to_string(self)?)?;
Ok(())
}
-
- fn load(path: &Path) -> Result<Self, Box<dyn Error>> {
- let contents = fs::read_to_string(path)?;
- toml::from_str(&contents).map_err(Into::into)
- }
}