From 6ff0e3653d481e573c8a592edf89fc174e74399a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 12 Oct 2021 00:20:42 +0200 Subject: [PATCH] changelog, add json5 --- CHANGELOG.md | 5 +++ Cargo.lock | 67 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + README.md | 4 +-- src/error.rs | 2 ++ src/store/group_config.rs | 10 +++--- src/store/mod.rs | 4 +-- 7 files changed, 84 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13cb2f0..759d546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v0.4.1 +- Add a translation system using the `locales` folder and `messages.json` +- Add more trace logging +- Config files are now parsed as JSON5 = comments are allowed + ## v0.3.0 - Changed config/storage format to directory-based, removed shared config mutex - Made more options configurable (timeouts, catch-up limits, etc) diff --git a/Cargo.lock b/Cargo.lock index 8e8767c..8c00e14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,6 +335,7 @@ dependencies = [ "elefren", "env_logger", "futures 0.3.16", + "json5", "log 0.4.14", "native-tls", "once_cell", @@ -764,6 +765,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -829,6 +841,12 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matches" version = "0.1.8" @@ -1105,6 +1123,49 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1 0.8.2", +] + [[package]] name = "phf" version = "0.7.24" @@ -2110,6 +2171,12 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicase" version = "1.4.2" diff --git a/Cargo.toml b/Cargo.toml index 33aeffb..22774c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ futures = "0.3" voca_rs = "1.13.0" regex = "1.5.4" once_cell = "1.8.0" +json5 = "0.4.1" native-tls = "0.2.8" websocket = "0.26.2" diff --git a/README.md b/README.md index 915ff64..f6d78fc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ In case you need to re-authenticate an existing group, do the same but use `-A` ### Editing config -**JSON does not support comments! Remove comments before using examples copied from this guide!** +**Staring v0.4.1, the config files support comments!** A typical setup could look like this: @@ -152,7 +152,7 @@ Note that changing config externally requires a restart. It's better to use slas When adding hashtags, *they must be entered as lowercase* and without the `#` symbol! -The file formats are quite self-explanatory (again, remove comments before copying, JSON does not support comments!) +The file formats are quite self-explanatory: **config.json** diff --git a/src/error.rs b/src/error.rs index dd3cb2b..b103740 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,6 +19,8 @@ pub enum GroupError { #[error(transparent)] Serializer(#[from] serde_json::Error), #[error(transparent)] + Serializer5(#[from] json5::Error), + #[error(transparent)] Elefren(#[from] elefren::Error), } diff --git a/src/store/group_config.rs b/src/store/group_config.rs index 5eddbea..838b925 100644 --- a/src/store/group_config.rs +++ b/src/store/group_config.rs @@ -163,7 +163,7 @@ async fn load_or_create_control_file(control_path: impl AsRef) -> Result) -> Result) -> Result(locale_json) { + if let Ok(mut tr) = json5::from_str::(locale_json) { debug!("Loaded locale: {}", locale_name); if !is_default {