Skip to content

Commit

Permalink
fix: saving empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Nov 18, 2024
1 parent 2d3c48e commit 4b7a48a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nvrs.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# nvrs
# https://github.com/adamperkowski/nvrs

[__config__]
oldver = "oldver.json"
newver = "newver.json"
Expand Down
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use std::{
struct KeysTable {
#[cfg(feature = "github")]
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub github: String,
#[cfg(feature = "gitlab")]
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub gitlab: String,
}

Expand Down Expand Up @@ -45,19 +47,24 @@ pub struct ConfigTable {
pub struct Package {
pub source: String,
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub host: String,

#[cfg(feature = "aur")]
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub aur: String,
#[cfg(feature = "github")]
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub github: String,
#[cfg(feature = "gitlab")]
#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub gitlab: String,

#[serde(default)]
#[serde(skip_serializing_if = "is_empty_string")]
pub prefix: String,
}

Expand Down Expand Up @@ -175,3 +182,7 @@ pub fn save(config_content: Config, path: PathBuf) -> Result<(), std::io::Error>
let content = format!("{}\n", toml::to_string(&config_content).unwrap());
file.write_all(content.as_bytes())
}

fn is_empty_string(value: &String) -> bool {
value.is_empty()
}

0 comments on commit 4b7a48a

Please sign in to comment.