@@ -25,96 +25,6 @@ namespace fs = std::filesystem;
2525
2626namespace
2727{
28- /* *
29- * A struct to configure a complete cxxopts CLI options
30- * F3D uses exclusively string options except for a few true boolean option (eg: `--version`)
31- * LongName: The long name, eg: `axis`
32- * ShortName: The short name, eg: `x`
33- * HelpText: The help text, for display only when using `--help`
34- * ValueHelper: Used in help but also to discrimate between boolean option or not
35- * ImplicitValue: The implicit value when option is provided without a value
36- */
37- struct CLIOption
38- {
39- std::string LongName;
40- std::string ShortName;
41- std::string HelpText;
42- std::string ValueHelper;
43- std::string ImplicitValue;
44- };
45-
46- /* *
47- * A struct to group option into categories
48- */
49- struct CLIGroup
50- {
51- std::string GroupName;
52- std::vector<CLIOption> Options;
53- };
54-
55- // ----------------------------------------------------------------------------
56- /* *
57- * Get all F3D CLI options except `--input`, `--define`, and `--reset`.
58- * Order of groups (in JSON) matters in the context of `--help`.
59- */
60- [[nodiscard]] std::vector<CLIGroup> GetAllCLIOptions ()
61- {
62- const auto cliOptionsJson = nlohmann::json::parse (F3D::CLI_OPTIONS_JSON);
63-
64- auto parseCliOptionJson = [](const nlohmann::json& cliOptionJson) -> CLIOption
65- {
66- CLIOption cliOption;
67- cliOption.LongName = cliOptionJson[" longName" ];
68- cliOption.ShortName = cliOptionJson[" shortName" ];
69- cliOption.HelpText = cliOptionJson[" helpText" ];
70- cliOption.ValueHelper = cliOptionJson[" valueHelper" ];
71- cliOption.ImplicitValue = cliOptionJson[" implicitValue" ];
72- return cliOption;
73- };
74-
75- auto parseCliGroupJson = [&parseCliOptionJson](const nlohmann::json& cliGroupJson) -> CLIGroup
76- {
77- CLIGroup cliGroup;
78- cliGroup.GroupName = cliGroupJson[" name" ];
79- for (const auto & cliOptionJson : cliGroupJson[" options" ])
80- {
81- #ifndef F3D_MODULE_DMON
82- if (cliOptionJson.value (" conditional" , " " ) == " F3D_MODULE_DMON" )
83- {
84- continue ;
85- }
86- #endif
87- #ifndef F3D_MODULE_UI
88- if (cliGroupJson.value (" conditional" , " " ) == " F3D_MODULE_UI" )
89- {
90- continue ;
91- }
92- #endif
93- if (cliGroup.GroupName == " Applicative" &&
94- std::set<std::string>{ " input" , " define" , " reset" }.count (cliOptionJson[" longName" ]) != 0 )
95- {
96- continue ;
97- }
98- cliGroup.Options .push_back (parseCliOptionJson (cliOptionJson));
99- }
100- return cliGroup;
101- };
102-
103- std::vector<CLIGroup> cliOptions;
104- for (const auto & cliGroupJson : cliOptionsJson[" groups" ])
105- {
106- #ifndef F3D_MODULE_RAYTRACING
107- if (cliGroupJson.value (" conditional" , " " ) == " F3D_MODULE_RAYTRACING" )
108- {
109- continue ;
110- }
111- #endif
112- cliOptions.push_back (parseCliGroupJson (cliGroupJson));
113- }
114-
115- return cliOptions;
116- }
117-
11828/* *
11929 * True boolean options need to be filtered out in ParseCLIOptions
12030 * Also filter out special options like `define` and `reset`
@@ -139,8 +49,7 @@ std::string CollapseName(const std::string_view& longName, const std::string_vie
13949}
14050
14151// ----------------------------------------------------------------------------
142- void PrintHelp (const std::string& execName, const cxxopts::Options& cxxOptions,
143- const std::vector<CLIGroup>& cliOptions)
52+ void PrintHelp (const std::string& execName, const cxxopts::Options& cxxOptions)
14453{
14554 const std::array<std::pair<std::string, std::string>, 4 > examples = { {
14655 { execName + " file.vtu -xtgans" ,
@@ -153,9 +62,9 @@ void PrintHelp(const std::string& execName, const cxxopts::Options& cxxOptions,
15362 } };
15463
15564 f3d::log::setUseColoring (false );
156- std::vector<std::string> orderedCLIGroupNames (cliOptions .size ());
157- std::transform (cliOptions .cbegin (), cliOptions .cend (), orderedCLIGroupNames.begin (),
158- [](const ::CLIGroup& cliGroup) { return cliGroup.GroupName ; });
65+ std::vector<std::string> orderedCLIGroupNames (F3D::CLIOptions .size ());
66+ std::transform (F3D::CLIOptions .cbegin (), F3D::CLIOptions .cend (), orderedCLIGroupNames.begin (),
67+ [](const F3D ::CLIGroup& cliGroup) { return cliGroup.GroupName ; });
15968 f3d::log::info (cxxOptions.help (orderedCLIGroupNames));
16069 f3d::log::info (" \n Examples:" );
16170 for (const auto & [cmd, desc] : examples)
@@ -372,14 +281,12 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions(
372281 std::vector<std::string> resets;
373282 auto cxxoptsResets = cxxopts::value<std::vector<std::string>>(resets);
374283
375- auto CLIOptions = GetAllCLIOptions ();
376-
377284 try
378285 {
379286 cxxopts::Options cxxOptions (execName, F3D::AppTitle);
380287 cxxOptions.custom_help (" [OPTIONS...]" );
381288
382- for (const ::CLIGroup& optionGroup : CLIOptions)
289+ for (const F3D ::CLIGroup& optionGroup : F3D:: CLIOptions)
383290 {
384291 auto group = cxxOptions.add_options (std::string (optionGroup.GroupName ));
385292
@@ -392,7 +299,7 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions(
392299 }
393300
394301 // Add each option to cxxopts
395- for (const ::CLIOption& cliOption : optionGroup.Options )
302+ for (const F3D ::CLIOption& cliOption : optionGroup.Options )
396303 {
397304 if (cliOption.ValueHelper .empty ())
398305 {
@@ -468,7 +375,7 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions(
468375 // Check boolean options and log them if any
469376 if (result.count (" help" ) > 0 )
470377 {
471- ::PrintHelp (execName, cxxOptions, CLIOptions );
378+ ::PrintHelp (execName, cxxOptions);
472379 throw F3DExNoProcess (" help requested" );
473380 }
474381 if (result.count (" version" ) > 0 )
0 commit comments