diff --git a/.gitignore b/.gitignore index c134d86..6399b8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +infoconv infoedit diff --git a/Makefile b/Makefile index 753f675..e1c304d 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,15 @@ -all: infoedit +all: infoconv infoedit + +infoconv: infoconv.cpp + $(CXX) -o infoconv -std=c++11 infoconv.cpp infoedit: infoedit.hpp infoedit.cpp - g++ -o infoedit -std=c++11 infoedit.cpp -lboost_program_options + $(CXX) -o infoedit -std=c++11 infoedit.cpp -lboost_program_options -install: infoedit - cp infoedit /usr/local/bin/infoedit +install: infoconv infoedit + install /usr/local/bin/infoconv infoconv + install /usr/local/bin/infoedit infoedit uninstall: + rm /usr/local/bin/infoconv rm /usr/local/bin/infoedit diff --git a/README.md b/README.md index 4c3f72b..29db39d 100644 --- a/README.md +++ b/README.md @@ -1,131 +1,6 @@ -A tool used to edit NFD configuration files -=========================================== +# Command Line Tools for Boost INFO Format -This tool is majorly developed for use in NFD integration tests. However, it can also used to -edit any INFO-formatted files. +This repository contains programs for working with [Boost INFO](https://www.boost.org/doc/libs/1_73_0/doc/html/property_tree/parsers.html#property_tree.parsers.info_parser) file format, as defined in Boost Property Tree library. -Each invocation of `infoedit` tool performs exactly one edit and the file is modified in place. -To perform multiple edits, `infoedit` tool should be invoked multiple times on the same file. - -## Usage ## - - infoedit [-f file] [-s|d|a|r path] [-v value] - -OPTIONS: - -* `-f file`: specifies a file to edit -* `-s path`: specifies a property-tree path to modify -* `-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 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 - ./infoedit -f nfd.conf -d tables.strategy_choice./ - ./infoedit -f nfd.conf -d authorizations - ./infoedit -f nfd.conf -a rib.localhost_security << +#include +#include +#include + +namespace pt = boost::property_tree; + +static void +usage() +{ + std::cerr << "USAGE\n" + " infoconv info2json < config.info > config.json\n" + " infoconv json2info < config.info > config.info\n"; +} + +static void +info2json() +{ + pt::ptree tree; + pt::info_parser::read_info(std::cin, tree); + pt::json_parser::write_json(std::cout, tree); +} + +static void +json2info() +{ + pt::ptree tree; + pt::json_parser::read_json(std::cin, tree); + pt::info_parser::write_info(std::cout, tree); +} + +int +main(int argc, char** argv) +{ + if (argc != 2) { + usage(); + return 2; + } + std::string action(argv[1]); + if (action == "info2json") { + info2json(); + } + else if (action == "json2info") { + json2info(); + } + else { + usage(); + return 2; + } +} diff --git a/infoconv.md b/infoconv.md new file mode 100644 index 0000000..24455fe --- /dev/null +++ b/infoconv.md @@ -0,0 +1,11 @@ +# infoconv: Convert between INFO and JSON + +**infoconv** program allows converting between Boost INFO and JSON formats. +One use case is to allow processing INFO files with JSON tools such as [jq](https://stedolan.github.io/jq/). + +Usage: + +``` +infoconv info2json < config.info > config.json +infoconv json2info < config.json > config.info +``` diff --git a/infoedit.md b/infoedit.md new file mode 100644 index 0000000..3cfb9aa --- /dev/null +++ b/infoedit.md @@ -0,0 +1,132 @@ +# A tool used to edit NFD configuration files + +This tool is majorly developed for use in NFD integration tests. However, it can also used to +edit any INFO-formatted files. + +Each invocation of `infoedit` tool performs exactly one edit and the file is modified in place. +To perform multiple edits, `infoedit` tool should be invoked multiple times on the same file. + +## Usage + + infoedit [-f file] [-s|d|a|r path] [-v value] + +OPTIONS: + +* `-f file`: specifies a file to edit +* `-s path`: specifies a property-tree path to modify +* `-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 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 + ./infoedit -f nfd.conf -d tables.strategy_choice./ + ./infoedit -f nfd.conf -d authorizations + ./infoedit -f nfd.conf -a rib.localhost_security <<