diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/args.cc | 2 | ||||
-rw-r--r-- | src/libutil/args.hh | 7 | ||||
-rw-r--r-- | src/libutil/args/root.hh | 4 | ||||
-rw-r--r-- | src/libutil/meson.build | 1 |
4 files changed, 13 insertions, 1 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 655b3e82f..1342e7c6a 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -64,7 +64,7 @@ RootArgs & Args::getRoot() while (p->parent) p = p->parent; - auto * res = dynamic_cast<RootArgs *>(p); + auto res = p->asRootArgs(); assert(res); return *res; } diff --git a/src/libutil/args.hh b/src/libutil/args.hh index 35a5238c0..71f8f88fa 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -244,6 +244,13 @@ protected: */ virtual void initialFlagsProcessed() {} + /** + * Returns this Args as a RootArgs if it is one, or \ref std::nullopt otherwise. + */ + virtual std::optional<std::reference_wrapper<RootArgs>> asRootArgs() { + return std::nullopt; + } + public: void addFlag(Flag && flag); diff --git a/src/libutil/args/root.hh b/src/libutil/args/root.hh index f8124eaff..499ee6df4 100644 --- a/src/libutil/args/root.hh +++ b/src/libutil/args/root.hh @@ -65,6 +65,10 @@ protected: */ std::set<ExperimentalFeature> flagExperimentalFeatures; + virtual std::optional<std::reference_wrapper<RootArgs>> asRootArgs() override { + return *this; + } + private: std::optional<std::string> needsCompletion(std::string_view s); diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 96450fbe2..cfdd0e52c 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -129,6 +129,7 @@ libutil = library( openssl, nlohmann_json, ], + cpp_pch : ['../pch/precompiled-headers.hh'], implicit_include_directories : true, install : true, ) |