Skip to content

feat!: Implement multi-backend support, including split-files and environment#71

Merged
Geod24 merged 3 commits intodlang-community:v3.x.xfrom
Geod24:mlang/Abstract
May 14, 2025
Merged

feat!: Implement multi-backend support, including split-files and environment#71
Geod24 merged 3 commits intodlang-community:v3.x.xfrom
Geod24:mlang/Abstract

Conversation

@Geod24
Copy link
Member

@Geod24 Geod24 commented Mar 7, 2025

This is a massive change that I've been wanting to do for a while. It will allow to cover all the missing use cases we have (read from env & CLI override).

Not ready for merge yet. Need

  1. A lot more tests;
  2. To be split up a bit;
  3. Support for an "override" backend (what CLIArgs was supposed to do);
  4. Clear up some code artifacts - E.g. the notion of backend and factory were from an earlier iteration which has been simplified;

@Geod24
Copy link
Member Author

Geod24 commented Mar 7, 2025

Might be of interest to you @VPanteleev-S7

Copy link
Contributor

@vpanteleev-sym vpanteleev-sym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

One security concern when reading stuff from the environment is to not do so automatically / implicitly, as the environment can sometimes be affected by outside parties, but looks like this is taken care of by requiring the prefix anyway.

foreach (kv; this.environ.byKeyValue()) {
if (!kv.key.startsWith(this.prefix)) continue;
const kname = getKeyName(kv.key, this.prefix);
scope kn = new EnvScalar(kname[0].toLower());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally snakeCase is converted to TITLE_CASE, but then the _ does become ambiguous. The gain in simplicity is much greater than the loss of readability though, so I think this is the right decision. Schema authors can group things in structs to improve readability as well.

@Geod24 Geod24 force-pushed the mlang/Abstract branch 2 times, most recently from ebe680f to 797ac20 Compare March 10, 2025 17:36
The environment backend is used to read values from the environment variable,
using a simple scheme (underscore-separated fields) for nesting.

Likewise the 'argument' backend use command-line provided arguments. Both of
those use a similar method relying on a key-parsing, hence there is a lot
of common code.

This will allow greater configurability for applications that wish to have
modern configuration override options.
@Geod24 Geod24 marked this pull request as ready for review May 13, 2025 06:53
Geod24 added 2 commits May 13, 2025 09:46
This special backend allows to combine multiple sources.
It can be used to either combine multiple configuration files
(with an order of priority) or multiple source (e.g. a file,
the environment, and the command line).
@Geod24
Copy link
Member Author

Geod24 commented May 13, 2025

New iteration is working. I think it could use an expression parser to make it possible to override elaborate nested member, but the scope of this PR is already quite large. @VPanteleev-S7 would you like to give it another look ? I haven't settled on a top-level API yet, I would like to expose something convenient instead of having to do the dance shown in the example, but that can be done in a later PR.

@Geod24 Geod24 merged commit 699128f into dlang-community:v3.x.x May 14, 2025
11 checks passed
@Geod24 Geod24 deleted the mlang/Abstract branch May 14, 2025 16:28
@codecov
Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v3.x.x@c4f16d9). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             v3.x.x   #71   +/-   ##
======================================
  Coverage          ?     0           
======================================
  Files             ?     0           
  Lines             ?     0           
  Branches          ?     0           
======================================
  Hits              ?     0           
  Misses            ?     0           
  Partials          ?     0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants