From eaba8cf790daf2a50514bcd0f6b380b100563bd3 Mon Sep 17 00:00:00 2001 From: Ashlesh Gawande Date: Tue, 19 Dec 2017 17:57:51 -0600 Subject: [PATCH] Add a new option to add duplicates to boost property tree --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++--- infoedit.cpp | 20 +++++++++++++++++++- infoedit.hpp | 3 +++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index df8a0e5..3d0ea8b 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,13 @@ OPTIONS: * `-f file`: specifies a file to edit * `-s path`: specifies a property-tree path to modify -* `-v value`: used with -s path, sets the value at the path +* `-p path`: specifies a property-tree path to add (duplicates can be added) +* `-v value`: used with -s path or -p path, sets the value at the path * `-d path`: deletes all subtrees matching the path * `-a path`: adds a subtree at the path; the subtree is read from stdin * `-r path`: replaces a subtree at the path; equivalent to -d path followed by -a path -## Sample command lines ## +## Sample commands for NFD ## ./infoedit -f nfd.conf -s general.user -v ndn.user ./infoedit -f nfd.conf -s tables.strategy_choice./site -v /localhost/nfd/strategy/broadcast @@ -87,4 +88,44 @@ OPTIONS: type any } } - } \ No newline at end of file + } + +## Sample commands for NLSR ## + + ./infoedit -f nlsr.conf -d security.cert-to-publish + ./infoedit -f nlsr.conf -p security.cert-to-publish security/root.cert + ./infoedit -f nlsr.conf -p security.cert-to-publish security/site.cert + ./infoedit -f nlsr.conf -p security.cert-to-publish security/operator.cert + ./infoedit -f nlsr.conf -p security.cert-to-publish security/router.cert + +### nlsr.conf used in above sample ### + + ... + security + { + ... + + ; cert-to-publish "root.cert" + + ; cert-to-publish "site.cert" + + ; cert-to-publish "operator.cert" + + cert-to-publish "router.cert" + } + +### nlsr.conf after carrying out all commands in above sample ### + + ... + security + { + ... + + cert-to-publish security/root.cert + + cert-to-publish security/site.cert + + cert-to-publish security/operator.cert + + cert-to-publish security/router.cert + } diff --git a/infoedit.cpp b/infoedit.cpp index 958b54f..3d4200e 100644 --- a/infoedit.cpp +++ b/infoedit.cpp @@ -49,6 +49,13 @@ InfoEditor::modify(const std::string& section, const std::string& value) return *this; } +InfoEditor& +InfoEditor::add(const std::string& section, const std::string& value) +{ + m_info.add(section.c_str(), value.c_str()); + return *this; +} + InfoEditor& InfoEditor::remove(const std::string& section) { @@ -102,7 +109,8 @@ main(int argc, char** argv) ("help,h", "print this help message") ("file,f", po::value(&configFile), "the file to edit") ("section,s", po::value(§ionPath), "the section to modify") - ("value,v", po::value(&value), "the value used to modify some section") + ("path,p", po::value(§ionPath), "the path to add - can be duplicate") + ("value,v", po::value(&value), "the value used to modify some section or add path") ("delete,d", po::value(§ionPath), "the sub tree to delete") ("add,a", po::value(§ionPath), "adds a sub tree") ("replace,r", po::value(§ionPath), "replace the sub tree") @@ -151,6 +159,15 @@ main(int argc, char** argv) editor.modify(sectionPath, value); } + if (vm.count("path") > 0) { + if (vm.count("value") == 0) { + std::cerr << "ERROR: value must be specified" << std::endl; + return 1; + } + + editor.add(sectionPath, value); + } + if (vm.count("delete") > 0) { editor.remove(sectionPath); } @@ -171,6 +188,7 @@ main(int argc, char** argv) editor.save(configFile); } catch (...) { + std::cerr << "Unable to save the edit to file" << std::endl; return 1; } diff --git a/infoedit.hpp b/infoedit.hpp index 6217c03..45ab8c7 100644 --- a/infoedit.hpp +++ b/infoedit.hpp @@ -42,6 +42,9 @@ public: InfoEditor& modify(const std::string& section, const std::string& value); + InfoEditor& + add(const std::string& section, const std::string& value); + InfoEditor& remove(const std::string& section);