diff --git a/Cargo.lock b/Cargo.lock index 01e8775..9ef0ddb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,6 +275,7 @@ dependencies = [ name = "cove-config" version = "0.6.1" dependencies = [ + "cove-macro", "serde", "toml", ] diff --git a/cove-config/Cargo.toml b/cove-config/Cargo.toml index 2e21781..11fcc5b 100644 --- a/cove-config/Cargo.toml +++ b/cove-config/Cargo.toml @@ -4,5 +4,7 @@ version = { workspace = true } edition = { workspace = true } [dependencies] +cove-macro = { path = "../cove-macro" } + serde = { version = "1.0.159", features = ["derive"] } toml = "0.7.3" diff --git a/cove-config/src/lib.rs b/cove-config/src/lib.rs index 561bd13..04b75bb 100644 --- a/cove-config/src/lib.rs +++ b/cove-config/src/lib.rs @@ -15,6 +15,8 @@ use std::collections::HashMap; use std::fs; use std::path::{Path, PathBuf}; +use cove_macro::Document; +use doc::{Doc, Document}; use serde::Deserialize; #[derive(Debug, Clone, Copy, Default, Deserialize)] @@ -25,31 +27,94 @@ pub enum RoomsSortOrder { Importance, } -#[derive(Debug, Clone, Default, Deserialize)] +impl Document for RoomsSortOrder { + fn doc() -> Doc { + let mut doc = String::doc(); + doc.value_info.values = Some(vec![ + // TODO Generate by serializing + "`alphabet`".to_string(), + "`importance`".to_string(), + ]); + doc + } +} + +// TODO Mark favourite rooms via printable ascii characters +#[derive(Debug, Clone, Default, Deserialize, Document)] pub struct EuphRoom { - // TODO Mark favourite rooms via printable ascii characters + /// Whether to automatically join this room on startup. #[serde(default)] + #[document(default = "`false`")] pub autojoin: bool, + + /// If set, cove will set this username upon joining if there is no username + /// associated with the current session. pub username: Option, + + /// If `euph.rooms..username` is set, this will force cove to set the + /// username even if there is already a different username associated with + /// the current session. #[serde(default)] + #[document(default = "`false`")] pub force_username: bool, + + /// If set, cove will try once to use this password to authenticate, should + /// the room be password-protected. pub password: Option, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Document)] pub struct Euph { + #[document(metavar = "room")] pub rooms: HashMap, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Document)] pub struct Config { + /// The directory that cove stores its data in when not running in ephemeral + /// mode. + /// + /// Relative paths are interpreted relative to the user's home directory. + /// + /// See also the `--data-dir` command line option. + #[document(default = "platform-dependent")] pub data_dir: Option, + + /// Whether to start in ephemeral mode. + /// + /// In ephemeral mode, cove doesn't store any data. It completely ignores + /// any options related to the data dir. + /// + /// See also the `--ephemeral` command line option. #[serde(default)] + #[document(default = "`false`")] pub ephemeral: bool, + + /// Whether to start in offline mode. + /// + /// In offline mode, cove won't automatically join rooms marked via the + /// `autojoin` option on startup. You can still join those rooms manually by + /// pressing `a` in the rooms list. + /// + /// See also the `--offline` command line option. #[serde(default)] + #[document(default = "`false`")] pub offline: bool, + + /// Initial sort order of rooms list. + /// + /// `alphabet` sorts rooms in alphabetic order. + /// + /// `importance` sorts rooms by the following criteria (in descending order + /// of priority): + /// + /// 1. connected rooms before unconnected rooms + /// 2. rooms with unread messages before rooms without + /// 3. alphabetic order #[serde(default)] + #[document(default = "`alphabet`")] pub rooms_sort_order: RoomsSortOrder, + // TODO Invoke external notification command? pub euph: Euph, }