refact(config)!: use toml instead of yaml

serde_yaml is deprecated and archived. We should not depend on that.
Therefore switching to toml.

Fixes #76.
This commit is contained in:
steven-omaha
2024-04-23 12:22:23 +02:00
parent 7b4f63d0ee
commit e9c3cec6d8
8 changed files with 35 additions and 67 deletions
Generated
+10 -42
View File
@@ -228,12 +228,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.8" version = "0.3.8"
@@ -244,28 +238,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.5.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.11" version = "1.0.11"
@@ -320,8 +298,8 @@ dependencies = [
"rust-apt", "rust-apt",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml",
"termios", "termios",
"toml",
"walkdir", "walkdir",
] ]
@@ -472,19 +450,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.11.1" version = "0.11.1"
@@ -530,6 +495,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "toml"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
@@ -548,12 +522,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"
version = "0.2.1" version = "0.2.1"
+9 -9
View File
@@ -130,7 +130,7 @@ This tree shows my pacdef repository (not the `pacdef` config dir).
│ ├── hostname_a │ ├── hostname_a
│ ├── hostname_b │ ├── hostname_b
│ └── hostname_c │ └── hostname_c
└── pacdef.yaml └── pacdef.toml
``` ```
- The `base` group holds all packages I need unconditionally, and includes things like zfs, - The `base` group holds all packages I need unconditionally, and includes things like zfs,
@@ -174,18 +174,18 @@ Use `--help` or the zsh completion to find the right aliases.
## Configuration ## Configuration
On first execution, it will create an empty config file under `$XDG_CONFIG_HOME/pacdef/pacdef.yaml`. On first execution, it will create an empty config file under `$XDG_CONFIG_HOME/pacdef/pacdef.toml`.
The following key-value pairs can be set. The following key-value pairs can be set.
The listed values are the defaults. The listed values are the defaults.
```yaml ```toml
aur_helper: paru # AUR helper to use on Arch Linux (paru, yay, ...) aur_helper = paru # AUR helper to use on Arch Linux (paru, yay, ...)
aur_rm_args: [] # additional args to pass to AUR helper when removing packages (optional) aur_rm_args = [] # additional args to pass to AUR helper when removing packages (optional)
disabled_backends: [] # backends that pacdef should not manage, e.g. ["python"], this can reduce runtime if the package manager is notoriously slow (like pip) disabled_backends = [] # backends that pacdef should not manage, e.g. ["python"], this can reduce runtime if the package manager is notoriously slow (like pip)
warn_not_symlinks: true # warn if a group file is not a symlink warn_not_symlinks = true # warn if a group file is not a symlink
flatpak_systemwide: true # whether flatpak packages should be installed system-wide or per user flatpak_systemwide = true # whether flatpak packages should be installed system-wide or per user
pip_binary: pip # choose whether to use pipx instead of pip for python package management (see below, 'pitfalls while using pipx') pip_binary = pip # choose whether to use pipx instead of pip for python package management (see below, 'pitfalls while using pipx')
``` ```
+1 -1
View File
@@ -23,7 +23,7 @@ enum_dispatch = "0.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
serde_yaml = "0.9" toml = "0.4"
# backends # backends
alpm = { version = "3.0", optional = true } alpm = { version = "3.0", optional = true }
+3 -3
View File
@@ -6,7 +6,7 @@ use anyhow::{bail, Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// Update the master README if fields change. // Update the master README if fields change.
/// Config for the program, as listed in `$XDG_CONFIG_HOME/pacdef/pacdef.yaml`. /// Config for the program, as listed in `$XDG_CONFIG_HOME/pacdef/pacdef.toml`.
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Config { pub struct Config {
/// The AUR helper to use for Arch Linux. /// The AUR helper to use for Arch Linux.
@@ -61,7 +61,7 @@ impl Config {
} }
}; };
serde_yaml::from_str(&content).context("parsing yaml config") toml::from_str(&content).context("parsing toml config")
} }
/// Save the instance of [`Config`] to disk. /// Save the instance of [`Config`] to disk.
@@ -70,7 +70,7 @@ impl Config {
/// ///
/// This function will return an error if the config file cannot be saved to disk. /// This function will return an error if the config file cannot be saved to disk.
pub fn save(&self, file: &Path) -> Result<()> { pub fn save(&self, file: &Path) -> Result<()> {
let content = serde_yaml::to_string(&self).context("converting Config to yaml")?; let content = toml::to_string(&self).context("converting Config to toml")?;
let parent = file.parent().context("getting parent of config dir")?; let parent = file.parent().context("getting parent of config dir")?;
if !parent.is_dir() { if !parent.is_dir() {
+3 -3
View File
@@ -25,9 +25,9 @@ use pacdef::path::{get_config_path, get_config_path_old_version, get_group_dir};
use pacdef::{Config, Error as PacdefError, Group}; use pacdef::{Config, Error as PacdefError, Group};
const MAJOR_UPDATE_MESSAGE: &str = "VERSION UPGRADE const MAJOR_UPDATE_MESSAGE: &str = "VERSION UPGRADE
You seem to have used version 0.x of pacdef before. You seem to have used version 1.x of pacdef before.
Version 1.x changes the syntax of the config files and the command line arguments. In version 2.0 the config file needed to be changed from yaml to toml.
Check out https://github.com/steven-omaha/pacdef for new syntax information. Check out https://github.com/steven-omaha/pacdef/blob/main/README.md#configuration for new syntax information.
This message will not appear again. This message will not appear again.
------"; ------";
+3 -3
View File
@@ -8,8 +8,8 @@ use std::{env, path::Path};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use path_absolutize::Absolutize; use path_absolutize::Absolutize;
const CONFIG_FILE_NAME: &str = "pacdef.yaml"; const CONFIG_FILE_NAME: &str = "pacdef.toml";
const CONFIG_FILE_NAME_OLD: &str = "pacdef.conf"; const CONFIG_FILE_NAME_OLD: &str = "pacdef.yaml";
/// Get the group directory where all group files are located. This is /// Get the group directory where all group files are located. This is
/// `$XDG_CONFIG_HOME/pacdef/groups`, which defaults to `$HOME/.config/pacdef/groups`. /// `$XDG_CONFIG_HOME/pacdef/groups`, which defaults to `$HOME/.config/pacdef/groups`.
@@ -76,7 +76,7 @@ pub fn get_home_dir() -> Result<PathBuf> {
Ok(env::var("HOME").context("getting $HOME variable")?.into()) Ok(env::var("HOME").context("getting $HOME variable")?.into())
} }
/// Get the path to the pacdef config file. This is `$XDG_CONFIG_HOME/pacdef/pacdef.yaml`. /// Get the path to the pacdef config file. This is `$XDG_CONFIG_HOME/pacdef/pacdef.toml`.
/// ///
/// # Errors /// # Errors
/// ///
+2 -2
View File
@@ -16,7 +16,7 @@ Each section contains one or more packages that can be installed respective pack
.SH CONFIGURATION .SH CONFIGURATION
Configure pacdef in its config file. See Configure pacdef in its config file. See
.BR pacdef.yaml(5). .BR pacdef.toml(5).
.SS GROUP FILE SYNTAX .SS GROUP FILE SYNTAX
@@ -163,5 +163,5 @@ Mostly 'steven-omaha'.
Contributors under https://github.com/steven-omaha/pacdef/graphs/contributors. Contributors under https://github.com/steven-omaha/pacdef/graphs/contributors.
.SH SEE ALSO .SH SEE ALSO
.BR pacdef.yaml(5) .BR pacdef.toml(5)
+4 -4
View File
@@ -1,11 +1,11 @@
.TH "PACDEF.YAML" "5" "2024\-04\-13" "pacdef v1\&.6\&.0" "Pacdef Manual" .TH "PACDEF.TOML" "5" "2024\-04\-13" "pacdef v1\&.6\&.0" "Pacdef Manual"
.SH NAME .SH NAME
pacdef.yaml \(em pacdef configuration file pacdef.toml \(em pacdef configuration file
.SH SYNOPSIS .SH SYNOPSIS
$XDG_CONFIG_HOME/pacdef/pacdef.yaml $XDG_CONFIG_HOME/pacdef/pacdef.toml
.br .br
$HOME/.config/pacdef/pacdef.yaml $HOME/.config/pacdef/pacdef.toml
. .
.SH DESCRIPTION .SH DESCRIPTION
This is the config file for This is the config file for