Document config

This commit is contained in:
Joscha 2023-04-20 20:35:27 +02:00
parent f2c3011888
commit 3d91d447c7
3 changed files with 72 additions and 4 deletions

1
Cargo.lock generated
View file

@ -275,6 +275,7 @@ dependencies = [
name = "cove-config" name = "cove-config"
version = "0.6.1" version = "0.6.1"
dependencies = [ dependencies = [
"cove-macro",
"serde", "serde",
"toml", "toml",
] ]

View file

@ -4,5 +4,7 @@ version = { workspace = true }
edition = { workspace = true } edition = { workspace = true }
[dependencies] [dependencies]
cove-macro = { path = "../cove-macro" }
serde = { version = "1.0.159", features = ["derive"] } serde = { version = "1.0.159", features = ["derive"] }
toml = "0.7.3" toml = "0.7.3"

View file

@ -15,6 +15,8 @@ use std::collections::HashMap;
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use cove_macro::Document;
use doc::{Doc, Document};
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Clone, Copy, Default, Deserialize)] #[derive(Debug, Clone, Copy, Default, Deserialize)]
@ -25,31 +27,94 @@ pub enum RoomsSortOrder {
Importance, 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 { pub struct EuphRoom {
// TODO Mark favourite rooms via printable ascii characters /// Whether to automatically join this room on startup.
#[serde(default)] #[serde(default)]
#[document(default = "`false`")]
pub autojoin: bool, 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<String>, pub username: Option<String>,
/// If `euph.rooms.<room>.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)] #[serde(default)]
#[document(default = "`false`")]
pub force_username: bool, 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<String>, pub password: Option<String>,
} }
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize, Document)]
pub struct Euph { pub struct Euph {
#[document(metavar = "room")]
pub rooms: HashMap<String, EuphRoom>, pub rooms: HashMap<String, EuphRoom>,
} }
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize, Document)]
pub struct Config { 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<PathBuf>, pub data_dir: Option<PathBuf>,
/// 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)] #[serde(default)]
#[document(default = "`false`")]
pub ephemeral: bool, 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)] #[serde(default)]
#[document(default = "`false`")]
pub offline: bool, 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)] #[serde(default)]
#[document(default = "`alphabet`")]
pub rooms_sort_order: RoomsSortOrder, pub rooms_sort_order: RoomsSortOrder,
// TODO Invoke external notification command? // TODO Invoke external notification command?
pub euph: Euph, pub euph: Euph,
} }