feat(cli): add migrate command, platform API, config management

This commit is contained in:
2026-05-25 15:20:13 +08:00
parent 4b79533c70
commit 4913d1c556
4 changed files with 242 additions and 76 deletions
+36
View File
@@ -0,0 +1,36 @@
use std::fs;
use std::path::Path;
#[derive(serde::Serialize, serde::Deserialize)]
pub struct Config {
pub api_base_url: String,
pub sn: Option<String>,
}
impl Config {
pub fn load(path: &Path) -> Self {
if path.exists() {
fs::read_to_string(path)
.ok()
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or_default()
} else {
Config::default()
}
}
pub fn save(&self, path: &Path) {
if let Ok(json) = serde_json::to_string_pretty(self) {
fs::write(path, json).ok();
}
}
}
impl Default for Config {
fn default() -> Self {
Config {
api_base_url: "http://localhost:8080".to_string(),
sn: None,
}
}
}