Add a new option to add duplicates to boost property tree

This commit is contained in:
Ashlesh Gawande authored and yoursunny committed 2017-12-19 19:36:39 -05:00
1 parent 4bb20d2e70
commit eaba8cf790
3 files changed
+66 -4

No files matched your search

+44 -3
View File
@@ -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
}
}
}
}
## 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
}
+19 -1
View File
@@ -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<std::string>(&configFile), "the file to edit")
("section,s", po::value<std::string>(&sectionPath), "the section to modify")
("value,v", po::value<std::string>(&value), "the value used to modify some section")
("path,p", po::value<std::string>(&sectionPath), "the path to add - can be duplicate")
("value,v", po::value<std::string>(&value), "the value used to modify some section or add path")
("delete,d", po::value<std::string>(&sectionPath), "the sub tree to delete")
("add,a", po::value<std::string>(&sectionPath), "adds a sub tree")
("replace,r", po::value<std::string>(&sectionPath), "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;
}
+3
View File
@@ -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);