mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
feat: provider wizards (init, login, new, import, config repo, bootstrap)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e599d48db8
commit
b86342b1d0
10 files changed
+795
-11
No files matched your search
@@ -1,11 +1,11 @@
|
||||
//! `config.toml` model, loading and validation (section 6 of the plan).
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub machine: Machine,
|
||||
pub root: Root,
|
||||
@@ -15,20 +15,21 @@ pub struct Config {
|
||||
pub groups: Vec<Group>,
|
||||
#[serde(default)]
|
||||
pub sync: Sync,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub config_repo: Option<ConfigRepo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Machine {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Root {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ProviderKind {
|
||||
Gitea,
|
||||
@@ -36,13 +37,14 @@ pub enum ProviderKind {
|
||||
Github,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Provider {
|
||||
pub kind: ProviderKind,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Layout {
|
||||
#[default]
|
||||
@@ -50,7 +52,7 @@ pub enum Layout {
|
||||
Plain,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Group {
|
||||
pub name: String,
|
||||
pub primary: String,
|
||||
@@ -62,7 +64,7 @@ pub struct Group {
|
||||
pub auto_materialize: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Sync {
|
||||
#[serde(default = "default_debounce")]
|
||||
pub snapshot_debounce_ms: u64,
|
||||
@@ -82,7 +84,7 @@ impl Default for Sync {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct ConfigRepo {
|
||||
pub provider: String,
|
||||
pub name: String,
|
||||
@@ -124,6 +126,18 @@ impl Config {
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
/// Writes the config atomically (temp file + rename).
|
||||
pub fn save(&self, path: &Path) -> Result<(), ConfigError> {
|
||||
let text = toml::to_string_pretty(self).map_err(|e| ConfigError::Parse(e.to_string()))?;
|
||||
let io = |e| ConfigError::Io(path.to_path_buf(), e);
|
||||
if let Some(dir) = path.parent() {
|
||||
std::fs::create_dir_all(dir).map_err(io)?;
|
||||
}
|
||||
let tmp = path.with_extension("toml.tmp");
|
||||
std::fs::write(&tmp, text).map_err(io)?;
|
||||
std::fs::rename(&tmp, path).map_err(io)
|
||||
}
|
||||
|
||||
pub fn load(path: &Path) -> Result<Config, ConfigError> {
|
||||
let text =
|
||||
std::fs::read_to_string(path).map_err(|e| ConfigError::Io(path.to_path_buf(), e))?;
|
||||
|
||||
Reference in new issue
Block a user