Add info about status to describe

Change-Id: I18b0ad156363f08b526be9d7765dad5383612a88
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index d01cb1d..8f419c3 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -142,7 +142,12 @@
 void Interpreter::operator()(const describe_& describe) const
 {
     auto path = absolutePathFromCommand(describe);
-    std::cout << path << ": " << buildTypeInfo(path) << std::endl;
+    auto status = m_datastore.schema()->status(path);
+    auto statusStr = status == yang::Status::Deprecated ? " (deprecated)" :
+        status == yang::Status::Obsolete ? " (obsolete)" :
+        "";
+
+    std::cout << path << ": " << buildTypeInfo(path) << statusStr << std::endl;
     if (auto description = m_datastore.schema()->description(path)) {
         std::cout << std::endl << *description << std::endl;
     }
diff --git a/src/schema.hpp b/src/schema.hpp
index 49fc5db..7ce24fb 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -24,6 +24,12 @@
     List,
     Leaf
 };
+
+enum class Status {
+    Current,
+    Deprecated,
+    Obsolete
+};
 }
 
 enum class Recursion {
@@ -62,6 +68,7 @@
     virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
     virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
     virtual std::optional<std::string> description(const std::string& location) const = 0;
+    virtual yang::Status status(const std::string& location) const = 0;
 
     virtual std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const = 0;
     virtual std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index dfb12e8..c86b232 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -197,6 +197,11 @@
     throw std::runtime_error{"StaticSchema::description not implemented"};
 }
 
+yang::Status StaticSchema::status([[maybe_unused]] const std::string& location) const
+{
+    throw std::runtime_error{"Internal error: StaticSchema::status(std::string) not implemented. The tests should not have called this overload."};
+}
+
 yang::NodeTypes StaticSchema::nodeType([[maybe_unused]] const std::string& path) const
 {
     throw std::runtime_error{"Internal error: StaticSchema::nodeType(std::string) not implemented. The tests should not have called this overload."};
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index 0d2bdff..947cc43 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -60,6 +60,7 @@
     std::set<std::string> childNodes(const schemaPath_& path, const Recursion) const override;
     std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override;
     std::optional<std::string> description(const std::string& path) const override;
+    yang::Status status(const std::string& location) const override;
 
     /** A helper for making tests a little bit easier. It returns all
      * identities which are based on the argument passed and which can then be
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 6290429..b134440 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -456,6 +456,18 @@
     return node->dsc() ? std::optional{node->dsc()} : std::nullopt;
 }
 
+yang::Status YangSchema::status(const std::string& location) const
+{
+    auto node = getSchemaNode(location.c_str());
+    if (node->flags() & LYS_STATUS_DEPRC) {
+        return yang::Status::Deprecated;
+    } else if (node->flags() & LYS_STATUS_OBSLT) {
+        return yang::Status::Obsolete;
+    } else {
+        return yang::Status::Current;
+    }
+}
+
 bool YangSchema::isConfig(const std::string& path) const
 {
     return getSchemaNode(path.c_str())->flags() & LYS_CONFIG_W;
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index c62ed20..fb0405b 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -46,6 +46,7 @@
     std::set<std::string> childNodes(const schemaPath_& path, const Recursion recursion) const override;
     std::set<std::string> moduleNodes(const module_& module, const Recursion recursion) const override;
     std::optional<std::string> description(const std::string& path) const override;
+    yang::Status status(const std::string& location) const override;
 
     void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*, const char*)>& clb);
 
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 598f115..69da16a 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -368,6 +368,36 @@
         }
     }
 
+    leaf obsoleteLeaf {
+        type int32;
+        status obsolete;
+    }
+
+    leaf deprecatedLeaf {
+        type int32;
+        status deprecated;
+    }
+
+    typedef deprecatedType {
+        type int32;
+        status deprecated;
+    }
+
+    leaf obsoleteLeafWithDeprecatedType {
+        type deprecatedType;
+        status obsolete;
+    }
+
+    typedef obsoleteType {
+        type int32;
+        status obsolete;
+    }
+
+    leaf obsoleteLeafWithObsoleteType {
+        type deprecatedType;
+        status obsolete;
+    }
+
 })";
 
 namespace std {
@@ -778,6 +808,10 @@
                        "example-schema:activeMappedPort",
                        "example-schema:activePort",
                        "example-schema:clockSpeed",
+                       "example-schema:deprecatedLeaf",
+                       "example-schema:obsoleteLeaf",
+                       "example-schema:obsoleteLeafWithDeprecatedType",
+                       "example-schema:obsoleteLeafWithObsoleteType",
                        "example-schema:systemStats"};
             }
 
@@ -856,6 +890,15 @@
             REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
         }
 
+        SECTION("status")
+        {
+            REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
+            REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
+            REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
+            REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
+            REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
+        }
+
         SECTION("units")
         {
             yang::LeafDataType expectedType;
@@ -966,6 +1009,7 @@
                     "example-schema:b",
                     "example-schema:carry",
                     "example-schema:clockSpeed",
+                    "example-schema:deprecatedLeaf",
                     "example-schema:direction",
                     "example-schema:duration",
                     "example-schema:ethernet",
@@ -991,6 +1035,9 @@
                     "example-schema:loopback",
                     "example-schema:myRpc",
                     "example-schema:numberOrString",
+                    "example-schema:obsoleteLeaf",
+                    "example-schema:obsoleteLeafWithDeprecatedType",
+                    "example-schema:obsoleteLeafWithObsoleteType",
                     "example-schema:pizzaIdentLeaf",
                     "example-schema:pizzaSize",
                     "example-schema:portMapping",
@@ -1018,6 +1065,7 @@
                     "/example-schema:b/b2/b3",
                     "/example-schema:carry",
                     "/example-schema:clockSpeed",
+                    "/example-schema:deprecatedLeaf",
                     "/example-schema:direction",
                     "/example-schema:duration",
                     "/example-schema:foodDrinkIdentLeaf",
@@ -1047,6 +1095,9 @@
                     "/example-schema:myRpc/input",
                     "/example-schema:myRpc/output",
                     "/example-schema:numberOrString",
+                    "/example-schema:obsoleteLeaf",
+                    "/example-schema:obsoleteLeafWithDeprecatedType",
+                    "/example-schema:obsoleteLeafWithObsoleteType",
                     "/example-schema:pizzaIdentLeaf",
                     "/example-schema:pizzaSize",
                     "/example-schema:portMapping",