changelog, add json5

This commit is contained in:
Ondřej Hruška 2021-10-12 00:20:42 +02:00
parent 4ddc26c6ca
commit 6ff0e3653d
No known key found for this signature in database
GPG key ID: 2C5FD5035250423D
7 changed files with 84 additions and 9 deletions

View file

@ -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)

67
Cargo.lock generated
View file

@ -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"

View file

@ -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"

View file

@ -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**

View file

@ -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),
}

View file

@ -163,7 +163,7 @@ async fn load_or_create_control_file(control_path: impl AsRef<Path>) -> Result<M
let mut dirty = false;
let mut control: MutableConfig = if control_path.is_file() {
let f = tokio::fs::read(&control_path).await?;
let mut control: MutableConfig = serde_json::from_slice(&f)?;
let mut control: MutableConfig = json5::from_str(&String::from_utf8_lossy(&f))?;
control._path = control_path.to_owned();
control
} else {
@ -185,7 +185,7 @@ async fn load_or_create_state_file(state_path: impl AsRef<Path>) -> Result<State
let mut dirty = false;
let mut state: StateConfig = if state_path.is_file() {
let f = tokio::fs::read(&state_path).await?;
let mut control: StateConfig = serde_json::from_slice(&f)?;
let mut control: StateConfig = json5::from_str(&String::from_utf8_lossy(&f))?;
control._path = state_path.to_owned();
control
} else {
@ -206,7 +206,7 @@ async fn load_locale_override_file(locale_path: impl AsRef<Path>) -> Result<Opti
let locale_path = locale_path.as_ref();
if locale_path.is_file() {
let f = tokio::fs::read(&locale_path).await?;
let opt : TranslationTable = serde_json::from_slice(&f)?;
let opt : TranslationTable = json5::from_str(&String::from_utf8_lossy(&f))?;
Ok(Some(opt))
} else {
Ok(None)
@ -275,7 +275,7 @@ impl GroupConfig {
let mut dirty = false;
let mut config: FixedConfig = if config_path.is_file() {
let f = tokio::fs::read(&config_path).await?;
let mut config: FixedConfig = serde_json::from_slice(&f)?;
let mut config: FixedConfig = json5::from_str(&String::from_utf8_lossy(&f))?;
config._path = config_path;
if config.appdata != appdata {
config.appdata = appdata;
@ -321,7 +321,7 @@ impl GroupConfig {
/* config */
let f = tokio::fs::read(&config_path).await?;
let mut config: FixedConfig = serde_json::from_slice(&f)?;
let mut config: FixedConfig = json5::from_str(&String::from_utf8_lossy(&f))?;
config._path = config_path;
/* control */

View file

@ -71,7 +71,7 @@ impl ConfigStore {
let config: CommonConfig = if let Some(cf) = &common_file {
debug!("Loading common config from {}", cf.display());
let f = tokio::fs::read(&cf).await?;
serde_json::from_slice(&f)?
json5::from_str(&String::from_utf8_lossy(&f))?
} else {
debug!("No common config file, using defaults");
CommonConfig::default()
@ -225,7 +225,7 @@ impl ConfigStore {
}
fn load_locale(&mut self, locale_name: &str, locale_json: &str, is_default: bool) {
if let Ok(mut tr) = serde_json::from_str::<TranslationTable>(locale_json) {
if let Ok(mut tr) = json5::from_str::<TranslationTable>(locale_json) {
debug!("Loaded locale: {}", locale_name);
if !is_default {