Skip to content

Commit

Permalink
env: attempt to parse nested configuration
Browse files Browse the repository at this point in the history
we use nested toml tables in our configuration, one table per what we think to be a logical section. However, because we want to add environment variables as configuration sources, we have to be able to parse nested dictionaries.
In order to do that, beside just using .prefix to filter out variables which don't concern us, we must also split the string of the variable name in keys, and for that we try to use the .split method
  • Loading branch information
albertotirla committed Mar 19, 2024
1 parent 3748321 commit 2b849e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 5 additions & 8 deletions odilia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ async fn main() -> eyre::Result<()> {
// Otherwise create it in XDG_CONFIG_HOME
//default configuration first, because that doesn't affect the priority outlined above
let figment = Figment::from(Serialized::defaults(ApplicationConfig::default()))
//environment variables
.join(Env::prefixed("ODILIA_"));
//environment variables
.join(Env::prefixed("ODILIA_").split("_"));
//cli override, if applicable
let figment = if let Some(path) = args.config {
figment.join(Toml::file(path))
} else {
figment
};
let figment =
if let Some(path) = args.config { figment.join(Toml::file(path)) } else { figment };
//create a config.toml file in `XDG_CONFIG_HOME`, to make it possible for the user to edit the default values, if it doesn't exist already
let xdg_dirs = xdg::BaseDirectories::with_prefix("odilia").expect(
"unable to find the odilia config directory according to the xdg dirs specification",
Expand All @@ -121,7 +118,7 @@ async fn main() -> eyre::Result<()> {
let config: ApplicationConfig = figment.extract()?;
tracing::debug!(?config, "configuration loaded successfully");

// Make sure applications with dynamic accessibility support do expose their AT-SPI2 interfaces.
// Make sure applications with dynamic accessibility support do expose their AT-SPI2 interfaces.

Check warning on line 121 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L88-L121

Added lines #L88 - L121 were not covered by tests
if let Err(e) = atspi_connection::set_session_accessibility(true).await {
tracing::debug!("Could not set AT-SPI2 IsEnabled property because: {}", e);
}
Expand Down
6 changes: 5 additions & 1 deletion odilia/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ impl ScreenReaderState {
let accessible_history = Mutex::new(CircularQueue::with_capacity(16));
let event_history = Mutex::new(CircularQueue::with_capacity(16));
let cache = Arc::new(Cache::new(atspi.connection().clone()));
ssip.send(SSIPRequest::SetRate(ssip_client_async::ClientScope::Current, config.speech().rate)).await?;
ssip.send(SSIPRequest::SetRate(
ssip_client_async::ClientScope::Current,
config.speech().rate,
))
.await?;
Ok(Self {
atspi,
dbus,
Expand Down

0 comments on commit 2b849e6

Please sign in to comment.