@@ -315,6 +315,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
315315{
316316 mSettings .exename = Path::getCurrentExecutablePath (argv[0 ]);
317317
318+ bool xmlOptionProvided = false ;
319+ bool outputFormatOptionProvided = false ;
320+
318321 // default to --check-level=normal from CLI for now
319322 mSettings .setCheckLevel (Settings::CheckLevel::normal);
320323
@@ -1001,6 +1004,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10011004 mSettings .outputFile = Path::simplifyPath (argv[i] + 14 );
10021005
10031006 else if (std::strncmp (argv[i], " --output-format=" , 16 ) == 0 ) {
1007+ if (xmlOptionProvided) {
1008+ outputFormatOptionMixingError ();
1009+ return Result::Fail;
1010+ }
10041011 const std::string format = argv[i] + 16 ;
10051012 // plist can not be handled here because it requires additional data
10061013 if (format == " text" )
@@ -1014,6 +1021,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10141021 return Result::Fail;
10151022 }
10161023 mSettings .plistOutput = " " ;
1024+ outputFormatOptionProvided = true ;
10171025 }
10181026
10191027
@@ -1486,11 +1494,20 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
14861494
14871495 // Write results in results.xml
14881496 else if (std::strcmp (argv[i], " --xml" ) == 0 ) {
1497+ if (outputFormatOptionProvided) {
1498+ outputFormatOptionMixingError ();
1499+ return Result::Fail;
1500+ }
14891501 mSettings .outputFormat = Settings::OutputFormat::xml;
1502+ xmlOptionProvided = true ;
14901503 }
14911504
14921505 // Define the XML file version (and enable XML output)
14931506 else if (std::strncmp (argv[i], " --xml-version=" , 14 ) == 0 ) {
1507+ if (outputFormatOptionProvided) {
1508+ outputFormatOptionMixingError ();
1509+ return Result::Fail;
1510+ }
14941511 int tmp;
14951512 if (!parseNumberArg (argv[i], 14 , tmp))
14961513 return Result::Fail;
@@ -1503,6 +1520,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15031520 mSettings .xml_version = tmp;
15041521 // Enable also XML if version is set
15051522 mSettings .outputFormat = Settings::OutputFormat::xml;
1523+ xmlOptionProvided = true ;
15061524 }
15071525
15081526 else {
@@ -2149,3 +2167,8 @@ std::list<FileWithDetails> CmdLineParser::filterFiles(const std::vector<std::str
21492167 });
21502168 return files;
21512169}
2170+
2171+ void CmdLineParser::outputFormatOptionMixingError () const
2172+ {
2173+ mLogger .printError (" '--output-format' and '--xml...' may not be used in conjunction." );
2174+ }
0 commit comments