]> granicus.if.org Git - icinga2/commitdiff
Add feature enable/disable helpers
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 25 Jun 2015 08:14:19 +0000 (10:14 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 25 Jun 2015 08:14:19 +0000 (10:14 +0200)
refs #9471

lib/cli/featureutility.cpp
lib/cli/featureutility.hpp

index d9f8ce437e53a1e2b35ab1e44def47bf9aa2e9f9..83786fd767f261036db2a97b31460d6c5d26f0c5 100644 (file)
@@ -244,6 +244,31 @@ bool FeatureUtility::GetFeatures(std::vector<String>& 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<String> 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<String>& features)
 {
        String feature = Utility::BaseName(feature_file);
index 2a9f7763dd4f78c600ed10a71363daf95b8337bd..d881d8807ce3dca0fd1cfbaa1d2ae7c2e262cc32 100644 (file)
@@ -45,10 +45,13 @@ public:
        static int ListFeatures(std::ostream& os = std::cout);
 
        static bool GetFeatures(std::vector<String>& 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<String>& features);
+       static bool CheckFeatureInternal(const String& feature, bool check_disabled);
 };
 
 }