From ff50a2b16d4f7b54c17857a0884fcbaa9e2d9312 Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Thu, 21 Nov 2024 17:26:51 +0100 Subject: [PATCH] Introduce an optional, simplified option parsing interface --- README.md | 19 +++++---- examples/libenvpp_option_example.cpp | 24 ++++++++++++ include/libenvpp/env.hpp | 58 +++++++++++++++++++++++++--- test/libenvpp_test.cpp | 24 +++++++++++- 4 files changed, 109 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a48f3fb..6955067 100644 --- a/README.md +++ b/README.md @@ -296,14 +296,13 @@ For the complete code see [examples/libenvpp_range_example.cpp](examples/libenvp ### Option Variables -Another frequent use-case is that a value is one of a given set of options. For this an environment variable can be registered with `register_[required]_option`, which takes a list of valid options, against which the value is checked. For example: +Another frequent use-case is that a value is one of a given set of options. For this an environment variable can be registered with `register_[required]_option`, which takes a list of either pairs of strings and corresponding options, or just valid options, against which the value is checked. For example: ```cpp enum class option { - first_choice, - second_choice, - third_choice, - default_choice, + first, + second, + fallback, }; int main() @@ -311,29 +310,29 @@ int main() auto pre = env::prefix("OPTION"); const auto option_id = - pre.register_option