@@ -917,6 +917,20 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
917917 else if (std::strncmp (argv[i], " --output-file=" , 14 ) == 0 )
918918 mSettings .outputFile = Path::simplifyPath (argv[i] + 14 );
919919
920+ else if (std::strncmp (argv[i], " --output-format=" , 16 ) == 0 ) {
921+ const std::string format = argv[i] + 16 ;
922+ if (format == " sarif" )
923+ mSettings .outputFormat = Settings::OutputFormat::sarif;
924+ else if (format == " xml" )
925+ mSettings .outputFormat = Settings::OutputFormat::xml;
926+ else {
927+ mLogger .printError (" argument to '--output-format=' must be 'sarif' or 'xml'." );
928+ return Result::Fail;
929+ }
930+ mSettings .xml = (mSettings .outputFormat == Settings::OutputFormat::xml);
931+ }
932+
933+
920934 // Experimental: limit execution time for extended valueflow analysis. basic valueflow analysis
921935 // is always executed.
922936 else if (std::strncmp (argv[i], " --performance-valueflow-max-time=" , 33 ) == 0 ) {
@@ -951,6 +965,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
951965
952966 // Write results in results.plist
953967 else if (std::strncmp (argv[i], " --plist-output=" , 15 ) == 0 ) {
968+ mSettings .outputFormat = Settings::OutputFormat::plist;
954969 mSettings .plistOutput = Path::simplifyPath (argv[i] + 15 );
955970 if (mSettings .plistOutput .empty ())
956971 mSettings .plistOutput = " ." ;
@@ -1362,12 +1377,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13621377 else if (std::strcmp (argv[i], " -v" ) == 0 || std::strcmp (argv[i], " --verbose" ) == 0 )
13631378 mSettings .verbose = true ;
13641379
1365- else if (std::strcmp (argv[i], " --sarif" ) == 0 )
1366- mSettings .sarif = true ;
1367-
13681380 // Write results in results.xml
1369- else if (std::strcmp (argv[i], " --xml" ) == 0 )
1381+ else if (std::strcmp (argv[i], " --xml" ) == 0 ) {
13701382 mSettings .xml = true ;
1383+ mSettings .outputFormat = Settings::OutputFormat::xml;
1384+ }
13711385
13721386 // Define the XML file version (and enable XML output)
13731387 else if (std::strncmp (argv[i], " --xml-version=" , 14 ) == 0 ) {
@@ -1383,6 +1397,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13831397 mSettings .xml_version = tmp;
13841398 // Enable also XML if version is set
13851399 mSettings .xml = true ;
1400+ mSettings .outputFormat = Settings::OutputFormat::xml;
13861401 }
13871402
13881403 else {
@@ -1628,6 +1643,10 @@ void CmdLineParser::printHelp() const
16281643 " is 2. A larger value will mean more errors can be found\n "
16291644 " but also means the analysis will be slower.\n "
16301645 " --output-file=<file> Write results to file, rather than standard error.\n "
1646+ " --output-format=<format>\n "
1647+ " Specify the output format. The available formats are:\n "
1648+ " * sarif\n "
1649+ " * xml\n "
16311650 " --platform=<type>, --platform=<file>\n "
16321651 " Specifies platform specific types and sizes. The\n "
16331652 " available builtin platforms are:\n "
0 commit comments