Skip to content

Commit

Permalink
iox-eclipse-iceoryx#404 Address review findings from Mathias Kraus
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice committed Feb 3, 2021
1 parent e3c26ec commit a0c9f40
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
10 changes: 6 additions & 4 deletions iceoryx_examples/iceperf/roudi_main_static_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ int main(int argc, char* argv[])
static constexpr uint32_t ONE_MEGABYTE = 1024U * 1024;

iox::config::CmdLineParserConfigFileOption cmdLineParser;
auto cmdLineArgs = cmdLineParser.parse(argc, argv).or_else([](iox::config::CmdLineParserResult& error) {
if (error == iox::config::CmdLineParserResult::UNKNOWN_OPTION_USED)
auto cmdLineArgs = cmdLineParser.parse(argc, argv);
if (cmdLineArgs.has_error())
{
if (cmdLineArgs.get_error() == iox::config::CmdLineParserResult::UNKNOWN_OPTION_USED)
{
iox::LogFatal() << "Unable to parse command line arguments!";
std::terminate();
return EXIT_FAILURE;
}
});
}

iox::RouDiConfig_t roudiConfig;
// roudiConfig.setDefaults(); can be used if you want to use the default config only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace config
enum class CmdLineParserResult
{
UNKNOWN_OPTION_USED,
USAGE_OUTPUT_REQUESTED /// @todo use this instead of CmdLineArgs_t.run after modularisation of RouDi
INFO_OUTPUT_ONLY /// @todo use this instead of CmdLineArgs_t.run after modularisation of RouDi
};

class CmdLineParser
Expand Down
29 changes: 15 additions & 14 deletions iceoryx_posh/source/roudi/application/roudi_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@ int main(int argc, char* argv[])
using iox::roudi::IceOryxRouDiApp;

iox::config::CmdLineParserConfigFileOption cmdLineParser;
auto cmdLineArgs = cmdLineParser.parse(argc, argv).or_else([](iox::config::CmdLineParserResult& error) {
if (error == iox::config::CmdLineParserResult::UNKNOWN_OPTION_USED)
auto cmdLineArgs = cmdLineParser.parse(argc, argv);
if (cmdLineArgs.has_error())
{
if (cmdLineArgs.get_error() == iox::config::CmdLineParserResult::UNKNOWN_OPTION_USED)
{
iox::LogFatal() << "Unable to parse command line arguments!";
std::terminate();
return EXIT_FAILURE;
}
});
}

iox::config::TomlRouDiConfigFileProvider configFileProvider(cmdLineArgs.value());

iox::RouDiConfig_t roudiConfig =
configFileProvider.parse()
.or_else([](iox::roudi::RouDiConfigFileParseError& parseResult) {
iox::LogFatal() << "Couldn't parse config file. Error: "
<< iox::cxx::convertEnumToString(iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS,
parseResult);
std::terminate();
})
.value();
auto roudiConfig = configFileProvider.parse();
if (roudiConfig.has_error())
{
iox::LogFatal() << "Couldn't parse config file. Error: "
<< iox::cxx::convertEnumToString(iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS,
roudiConfig.get_error());
return EXIT_FAILURE;
}

IceOryxRouDiApp roudi(cmdLineArgs.value(), roudiConfig);
IceOryxRouDiApp roudi(cmdLineArgs.value(), roudiConfig.value());

return roudi.run();
}
8 changes: 4 additions & 4 deletions iceoryx_posh/test/moduletests/test_roudi_cmd_line_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ TEST_F(CmdLineParser_test, UniqueIdLongOptionLeadsToCorrectUniqueId)
char* args[numberOfArgs];
char appName[] = "./foo";
char option[] = "--unique-roudi-id";
char wrongValue[] = "4242";
char value[] = "4242";
args[0] = &appName[0];
args[1] = &option[0];
args[2] = &wrongValue[0];
args[2] = &value[0];

iox::config::CmdLineParser sut;
auto result = sut.parse(numberOfArgs, args);
Expand All @@ -396,10 +396,10 @@ TEST_F(CmdLineParser_test, UniqueIdShortOptionLeadsToCorrectUniqueId)
char* args[numberOfArgs];
char appName[] = "./foo";
char option[] = "-u";
char wrongValue[] = "4242";
char value[] = "4242";
args[0] = &appName[0];
args[1] = &option[0];
args[2] = &wrongValue[0];
args[2] = &value[0];

iox::config::CmdLineParser sut;
auto result = sut.parse(numberOfArgs, args);
Expand Down

0 comments on commit a0c9f40

Please sign in to comment.