Add discard command
Change-Id: Ie2243188694657665240769d93b2835034e48c3a
diff --git a/src/ast_commands.hpp b/src/ast_commands.hpp
index 966f170..a1c377b 100644
--- a/src/ast_commands.hpp
+++ b/src/ast_commands.hpp
@@ -33,6 +33,10 @@
Recursive
};
+struct discard_ : x3::position_tagged {
+ bool operator==(const discard_& b) const;
+};
+
struct ls_ : x3::position_tagged {
bool operator==(const ls_& b) const;
std::vector<LsOption> m_options;
@@ -69,7 +73,7 @@
boost::optional<path_> m_path;
};
-using command_ = boost::variant<ls_, cd_, create_, delete_, set_, commit_, get_>;
+using command_ = boost::variant<discard_, ls_, cd_, create_, delete_, set_, commit_, get_>;
BOOST_FUSION_ADAPT_STRUCT(ls_, m_options, m_path)
BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
@@ -78,4 +82,5 @@
BOOST_FUSION_ADAPT_STRUCT(enum_, m_value)
BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data)
BOOST_FUSION_ADAPT_STRUCT(commit_)
+BOOST_FUSION_ADAPT_STRUCT(discard_)
BOOST_FUSION_ADAPT_STRUCT(get_, m_path)
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index 580ea86..b19ece0 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -214,6 +214,7 @@
}
};
+struct discard_class;
struct ls_class;
diff --git a/src/datastore_access.hpp b/src/datastore_access.hpp
index 7259273..9cd6a70 100644
--- a/src/datastore_access.hpp
+++ b/src/datastore_access.hpp
@@ -25,4 +25,5 @@
virtual void deletePresenceContainer(const std::string& path) = 0;
virtual void commitChanges() = 0;
+ virtual void discardChanges() = 0;
};
diff --git a/src/grammars.hpp b/src/grammars.hpp
index 688394e..03753e8 100644
--- a/src/grammars.hpp
+++ b/src/grammars.hpp
@@ -36,6 +36,7 @@
x3::rule<leaf_data_uint_class, uint32_t> const leaf_data_uint = "leaf_data_uint";
x3::rule<leaf_data_string_class, std::string> const leaf_data_string = "leaf_data_string";
+x3::rule<discard_class, discard_> const discard = "discard";
x3::rule<ls_class, ls_> const ls = "ls";
x3::rule<cd_class, cd_> const cd = "cd";
x3::rule<set_class, set_> const set = "set";
@@ -176,8 +177,11 @@
auto const commit_def =
lit("commit") >> x3::attr(commit_());
+auto const discard_def =
+ lit("discard") >> x3::attr(discard_());
+
auto const command_def =
- x3::expect[cd | create | delete_rule | set | commit | get | ls] >> x3::eoi;
+ x3::expect[cd | create | delete_rule | set | commit | get | ls | discard] >> x3::eoi;
#if __clang__
#pragma GCC diagnostic pop
@@ -209,6 +213,7 @@
BOOST_SPIRIT_DEFINE(commit)
BOOST_SPIRIT_DEFINE(get)
BOOST_SPIRIT_DEFINE(ls)
+BOOST_SPIRIT_DEFINE(discard)
BOOST_SPIRIT_DEFINE(cd)
BOOST_SPIRIT_DEFINE(create)
BOOST_SPIRIT_DEFINE(delete_rule)
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index bdeecf9..452bc74 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -29,6 +29,11 @@
m_datastore.commitChanges();
}
+void Interpreter::operator()(const discard_&) const
+{
+ m_datastore.discardChanges();
+}
+
void Interpreter::operator()(const set_& set) const
{
m_datastore.setLeaf(absolutePathFromCommand(set), set.m_data);
diff --git a/src/interpreter.hpp b/src/interpreter.hpp
index 262b037..0940ad5 100644
--- a/src/interpreter.hpp
+++ b/src/interpreter.hpp
@@ -22,6 +22,7 @@
void operator()(const create_&) const;
void operator()(const delete_&) const;
void operator()(const ls_&) const;
+ void operator()(const discard_&) const;
private:
template <typename T>
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 27ddba2..57d1cb3 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -131,6 +131,11 @@
m_session->commit();
}
+void SysrepoAccess::discardChanges()
+{
+ m_session->discard_changes();
+}
+
std::string SysrepoAccess::fetchSchema(const char* module, const char* revision, const char* submodule)
{
auto schema = m_session->get_schema(module, revision, submodule, SR_SCHEMA_YANG); // FIXME: maybe we should use get_submodule_schema for submodules?
diff --git a/src/sysrepo_access.hpp b/src/sysrepo_access.hpp
index fb1f713..13b4ace 100644
--- a/src/sysrepo_access.hpp
+++ b/src/sysrepo_access.hpp
@@ -36,6 +36,7 @@
std::vector<std::string> listImplementedSchemas();
void commitChanges() override;
+ void discardChanges() override;
std::shared_ptr<Schema> schema();