From: Michael Friedrich Date: Thu, 25 Jun 2015 08:14:19 +0000 (+0200) Subject: Add feature enable/disable helpers X-Git-Tag: v2.4.0~566 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f43162efa4c17b3339a04909bd45b6bcdddf33a;p=icinga2 Add feature enable/disable helpers refs #9471 --- diff --git a/lib/cli/featureutility.cpp b/lib/cli/featureutility.cpp index d9f8ce437..83786fd76 100644 --- a/lib/cli/featureutility.cpp +++ b/lib/cli/featureutility.cpp @@ -244,6 +244,31 @@ bool FeatureUtility::GetFeatures(std::vector& features, bool get_disable return true; } +bool FeatureUtility::CheckFeatureEnabled(const String& feature) +{ + return CheckFeatureInternal(feature, false); +} + +bool FeatureUtility::CheckFeatureDisabled(const String& feature) +{ + return CheckFeatureInternal(feature, true); +} + +bool FeatureUtility::CheckFeatureInternal(const String& feature, bool check_disabled) +{ + std::vector features; + + if (!FeatureUtility::GetFeatures(features, check_disabled)) + return false; + + BOOST_FOREACH(const String& check_feature, features) { + if (check_feature == feature) + return true; + } + + return false; +} + void FeatureUtility::CollectFeatures(const String& feature_file, std::vector& features) { String feature = Utility::BaseName(feature_file); diff --git a/lib/cli/featureutility.hpp b/lib/cli/featureutility.hpp index 2a9f7763d..d881d8807 100644 --- a/lib/cli/featureutility.hpp +++ b/lib/cli/featureutility.hpp @@ -45,10 +45,13 @@ public: static int ListFeatures(std::ostream& os = std::cout); static bool GetFeatures(std::vector& features, bool enable); + static bool CheckFeatureEnabled(const String& feature); + static bool CheckFeatureDisabled(const String& feature); private: FeatureUtility(void); static void CollectFeatures(const String& feature_file, std::vector& features); + static bool CheckFeatureInternal(const String& feature, bool check_disabled); }; }