Skip to content

Commit

Permalink
feat: Simplify state setup using enum and add documentation
Browse files Browse the repository at this point in the history
Signed-off-by: David Runge <[email protected]>
  • Loading branch information
dvzrv committed Sep 27, 2023
1 parent d39915a commit 3171e93
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 222 deletions.
14 changes: 12 additions & 2 deletions dist/caterpillar.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# SPDX-FileCopyrightText: 2023 David Runge <[email protected]>
# SPDX-License-Identifier: LGPL-3.0-or-later

# This configuration file documents the built-in defaults for caterpillar

# Run non-interactively on first start.
# This automatically searches for an update, installs a matching update if found and reboots.
autorun = true

# The file extension to search for at the top-level or in an override_dir on a mounted filesystem.
bundle_extension = "raucb"

# The regular expression used to match for block devices discovered by udisks2 over D-Bus.
device_regex = "^/org/freedesktop/UDisks2/block_devices/sd[a-z]{1}[1-9]{1}[0-9]*?$"
interactive_on_first_run = false

# The name of a directory in which override updates are searched for.
# Valid updates in this directory have precedence over those found in the top-level filesystem.
# This is useful for downgrade scenarios.
override_dir = "override"
reboot = true
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use config::{Config, ConfigError, File};

pub const DEVICE_REGEX: &str = "^/org/freedesktop/UDisks2/block_devices/sd[a-z]{1}[1-9]{1}[0-9]*?$";

/// Read the configuration for the application
///
/// This uses built-in defaults, which can be overridden with an optional configuration file found in /etc/caterpillar/caterpillar.toml
pub async fn read_config() -> Result<Config, ConfigError> {
Config::builder()
.set_default("autorun", true)?
// by default we want to match any block device
.set_default("bundle_extension", "raucb")?
.set_default("device_regex", DEVICE_REGEX)?
.set_default("interactive_on_first_run", true)?
.set_default("override_dir", "override")?
.set_default("reboot", true)?
.add_source(File::with_name("/etc/caterpillar/caterpillar").required(false))
.add_source(config::Environment::with_prefix("CATERPILLAR"))
.build()
Expand Down
Loading

0 comments on commit 3171e93

Please sign in to comment.