File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -713,6 +713,7 @@ set(openPMD_TEST_NAMES
713713set (openPMD_CLI_TOOL_NAMES
714714 ls
715715 convert-toml-json
716+ merge-json
716717)
717718set (openPMD_PYTHON_CLI_TOOL_NAMES
718719 pipe
Original file line number Diff line number Diff line change @@ -59,6 +59,15 @@ struct switch_::other_type<json::SupportedLanguages::TOML>
5959template <typename FromFormatToFormat>
6060class convert_json_toml
6161{
62+ static void print (toml::value &val)
63+ {
64+ namespace json = openPMD::json;
65+ std::cout << json::format_toml (val);
66+ }
67+ static void print (nlohmann::json const &val)
68+ {
69+ std::cout << val << ' \n ' ;
70+ }
6271 static void
6372 with_parsed_cmdline_args (openPMD::json::ParsedConfig parsed_config)
6473 {
@@ -68,13 +77,17 @@ class convert_json_toml
6877 {
6978 using SL = json::SupportedLanguages;
7079 case SL::JSON: {
71- auto asToml = json::jsonToToml (config);
72- std::cout << json::format_toml (asToml);
80+ auto for_print =
81+ FromFormatToFormat::template call<SL::JSON>(std::move (config));
82+ print (for_print);
83+ }
84+ break ;
85+ case SL::TOML: {
86+ auto for_print =
87+ FromFormatToFormat::template call<SL::TOML>(std::move (config));
88+ print (for_print);
7389 }
7490 break ;
75- case SL::TOML:
76- std::cout << config << ' \n ' ;
77- break ;
7891 }
7992 }
8093
Original file line number Diff line number Diff line change @@ -17,6 +17,6 @@ equivalently from TOML to JSON.
1717
1818int main (int argc, char const **argv)
1919{
20- convert_json_toml<from_format_to_format::ID >::run_application (
20+ convert_json_toml<from_format_to_format::switch_ >::run_application (
2121 argc, argv, print_help_message);
2222}
Original file line number Diff line number Diff line change 1+ #include " openPMD/cli/convert-toml-json.hpp"
2+
3+ void print_help_message (char const *program_name)
4+ {
5+ std::cout << " Usage: " << std::string (program_name) << R"( [json_or_toml]+
6+ 'json_or_toml' can be a JSON or TOML dataset specified inline or a reference
7+ to a file prepended by an '@'.
8+ Inline datasets will be interpreted as JSON if they start with an '{', as TOML
9+ otherwise. Datasets from a file will be interpreted as JSON or TOML depending
10+ on the file ending '.json' or '.toml' respectively.
11+ Inline dataset specifications can be replaced by input read from stdin.
12+
13+ If the JSON/TOML files are mixed, then the output type (JSON or TOML) will be
14+ determined by the type of the first file.
15+ )" ;
16+ }
17+
18+ int main (int argc, char const **argv)
19+ {
20+ convert_json_toml<from_format_to_format::ID>::run_application (
21+ argc, argv, print_help_message);
22+ }
You can’t perform that action at this time.
0 commit comments