Extract config into cove-config crate
This commit is contained in:
parent
288a5f97dd
commit
5b5370d2df
9 changed files with 37 additions and 15 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -249,6 +249,7 @@ dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"clap",
|
"clap",
|
||||||
"cookie",
|
"cookie",
|
||||||
|
"cove-config",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"directories",
|
"directories",
|
||||||
"edit",
|
"edit",
|
||||||
|
|
@ -259,19 +260,25 @@ dependencies = [
|
||||||
"open",
|
"open",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite",
|
||||||
"toml",
|
|
||||||
"toss",
|
"toss",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"vault",
|
"vault",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cove-config"
|
||||||
|
version = "0.6.1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = ["cove"]
|
members = ["cove", "cove-*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
|
|
|
||||||
8
cove-config/Cargo.toml
Normal file
8
cove-config/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "cove-config"
|
||||||
|
version = { workspace = true }
|
||||||
|
edition = { workspace = true }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1.0.159", features = ["derive"] }
|
||||||
|
toml = "0.7.3"
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
|
#![forbid(unsafe_code)]
|
||||||
|
// Rustc lint groups
|
||||||
|
#![warn(future_incompatible)]
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
|
#![warn(unused)]
|
||||||
|
// Rustc lints
|
||||||
|
#![warn(noop_method_call)]
|
||||||
|
#![warn(single_use_lifetimes)]
|
||||||
|
// Clippy lints
|
||||||
|
#![warn(clippy::use_self)]
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::macros::ok_or_return;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, Deserialize)]
|
#[derive(Debug, Clone, Copy, Default, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum RoomsSortOrder {
|
pub enum RoomsSortOrder {
|
||||||
|
|
@ -45,7 +54,7 @@ pub struct Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load(path: &Path) -> Self {
|
pub fn load(path: &Path) -> Self {
|
||||||
let content = ok_or_return!(fs::read_to_string(path), Self::default());
|
let Ok(content) = fs::read_to_string(path) else { return Self::default(); };
|
||||||
match toml::from_str(&content) {
|
match toml::from_str(&content) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -4,6 +4,8 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cove-config = { path = "../cove-config" }
|
||||||
|
|
||||||
anyhow = "1.0.70"
|
anyhow = "1.0.70"
|
||||||
async-trait = "0.1.68"
|
async-trait = "0.1.68"
|
||||||
clap = { version = "4.2.1", features = ["derive", "deprecated"] }
|
clap = { version = "4.2.1", features = ["derive", "deprecated"] }
|
||||||
|
|
@ -17,11 +19,9 @@ once_cell = "1.17.1"
|
||||||
open = "4.0.1"
|
open = "4.0.1"
|
||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
rusqlite = { version = "0.29.0", features = ["bundled", "time"] }
|
rusqlite = { version = "0.29.0", features = ["bundled", "time"] }
|
||||||
serde = { version = "1.0.159", features = ["derive"] }
|
|
||||||
serde_json = "1.0.95"
|
serde_json = "1.0.95"
|
||||||
thiserror = "1.0.40"
|
thiserror = "1.0.40"
|
||||||
tokio = { version = "1.27.0", features = ["full"] }
|
tokio = { version = "1.27.0", features = ["full"] }
|
||||||
toml = "0.7.3"
|
|
||||||
unicode-segmentation = "1.10.1"
|
unicode-segmentation = "1.10.1"
|
||||||
unicode-width = "0.1.10"
|
unicode-width = "0.1.10"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
// TODO Time zones other than UTC
|
// TODO Time zones other than UTC
|
||||||
// TODO Fix password room auth
|
// TODO Fix password room auth
|
||||||
|
|
||||||
mod config;
|
|
||||||
mod euph;
|
mod euph;
|
||||||
mod export;
|
mod export;
|
||||||
mod logger;
|
mod logger;
|
||||||
|
|
@ -28,12 +27,12 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cookie::CookieJar;
|
use cookie::CookieJar;
|
||||||
|
use cove_config::Config;
|
||||||
use directories::{BaseDirs, ProjectDirs};
|
use directories::{BaseDirs, ProjectDirs};
|
||||||
use log::info;
|
use log::info;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use toss::Terminal;
|
use toss::Terminal;
|
||||||
|
|
||||||
use crate::config::Config;
|
|
||||||
use crate::logger::Logger;
|
use crate::logger::Logger;
|
||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
use crate::vault::Vault;
|
use crate::vault::Vault;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use std::io;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use cove_config::Config;
|
||||||
use parking_lot::FairMutex;
|
use parking_lot::FairMutex;
|
||||||
use tokio::sync::mpsc::error::TryRecvError;
|
use tokio::sync::mpsc::error::TryRecvError;
|
||||||
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
||||||
|
|
@ -17,7 +18,6 @@ use tokio::task;
|
||||||
use toss::widgets::BoxedAsync;
|
use toss::widgets::BoxedAsync;
|
||||||
use toss::{Terminal, WidgetExt};
|
use toss::{Terminal, WidgetExt};
|
||||||
|
|
||||||
use crate::config::Config;
|
|
||||||
use crate::logger::{LogMsg, Logger};
|
use crate::logger::{LogMsg, Logger};
|
||||||
use crate::macros::{logging_unwrap, ok_or_return, some_or_return};
|
use crate::macros::{logging_unwrap, ok_or_return, some_or_return};
|
||||||
use crate::util::InfallibleExt;
|
use crate::util::InfallibleExt;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ use tokio::sync::{mpsc, oneshot};
|
||||||
use toss::widgets::{BoxedAsync, EditorState, Join2, Layer, Text};
|
use toss::widgets::{BoxedAsync, EditorState, Join2, Layer, Text};
|
||||||
use toss::{Style, Styled, Terminal, Widget, WidgetExt};
|
use toss::{Style, Styled, Terminal, Widget, WidgetExt};
|
||||||
|
|
||||||
use crate::config;
|
|
||||||
use crate::euph;
|
use crate::euph;
|
||||||
use crate::macros::logging_unwrap;
|
use crate::macros::logging_unwrap;
|
||||||
use crate::ui::chat::{ChatState, Reaction};
|
use crate::ui::chat::{ChatState, Reaction};
|
||||||
|
|
@ -46,7 +45,7 @@ type EuphChatState = ChatState<euph::SmallMessage, EuphRoomVault>;
|
||||||
|
|
||||||
pub struct EuphRoom {
|
pub struct EuphRoom {
|
||||||
server_config: ServerConfig,
|
server_config: ServerConfig,
|
||||||
config: config::EuphRoom,
|
config: cove_config::EuphRoom,
|
||||||
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
|
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
|
||||||
|
|
||||||
room: Option<euph::Room>,
|
room: Option<euph::Room>,
|
||||||
|
|
@ -64,7 +63,7 @@ pub struct EuphRoom {
|
||||||
impl EuphRoom {
|
impl EuphRoom {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
server_config: ServerConfig,
|
server_config: ServerConfig,
|
||||||
config: config::EuphRoom,
|
config: cove_config::EuphRoom,
|
||||||
vault: EuphRoomVault,
|
vault: EuphRoomVault,
|
||||||
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
|
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use cove_config::{Config, RoomsSortOrder};
|
||||||
use crossterm::style::Stylize;
|
use crossterm::style::Stylize;
|
||||||
use euphoxide::api::SessionType;
|
use euphoxide::api::SessionType;
|
||||||
use euphoxide::bot::instance::{Event, ServerConfig};
|
use euphoxide::bot::instance::{Event, ServerConfig};
|
||||||
|
|
@ -11,7 +12,6 @@ use tokio::sync::mpsc;
|
||||||
use toss::widgets::{BoxedAsync, EditorState, Empty, Join2, Text};
|
use toss::widgets::{BoxedAsync, EditorState, Empty, Join2, Text};
|
||||||
use toss::{Style, Styled, Terminal, Widget, WidgetExt};
|
use toss::{Style, Styled, Terminal, Widget, WidgetExt};
|
||||||
|
|
||||||
use crate::config::{Config, RoomsSortOrder};
|
|
||||||
use crate::euph;
|
use crate::euph;
|
||||||
use crate::macros::logging_unwrap;
|
use crate::macros::logging_unwrap;
|
||||||
use crate::vault::Vault;
|
use crate::vault::Vault;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue