From 3952a05ad3282535066d3d3dcc8af3102dbbc074 Mon Sep 17 00:00:00 2001 From: Volker Christian Date: Tue, 23 Sep 2025 20:45:22 +0200 Subject: [PATCH] Add a required_callback to inject user defined requirement checks In some situations the standard requirement checks are not sufficient. In such cases the user can provide a required_callback doing additional requirement checks. This callback is executed after all standard requirement checks. --- include/CLI/App.hpp | 10 ++++++++++ include/CLI/impl/App_inl.hpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index d35e9b9d2..595c40a40 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -146,6 +146,9 @@ class App { /// This is a function that runs when all processing has completed std::function final_callback_{}; + /// This is a function tat runs after all standard requirement checks havv been processed + std::function require_callback_{}; + ///@} /// @name Options ///@{ @@ -376,6 +379,13 @@ class App { return this; } + /// Set a callback to execute after all standard requirement checks have been processed + /// + App *require_callback(std::function req_callback) { + require_callback_ = std::move(req_callback); + return this; + } + /// Set a name for the app (empty will use parser to set the name) App *name(std::string app_name = ""); diff --git a/include/CLI/impl/App_inl.hpp b/include/CLI/impl/App_inl.hpp index 614805dde..244a37871 100644 --- a/include/CLI/impl/App_inl.hpp +++ b/include/CLI/impl/App_inl.hpp @@ -1410,6 +1410,10 @@ CLI11_INLINE void App::_process_requirements() { throw(CLI::RequiredError(sub->get_display_name())); } } + + if (require_callback_) { + require_callback_(); + } } CLI11_INLINE void App::_process() {