Skip to content

Commit

Permalink
Merge pull request #248 from saturner74/vs2019
Browse files Browse the repository at this point in the history
Be able to exit with non-zero error code when warnings are found
  • Loading branch information
JarLob committed May 31, 2022
2 parents d04d5bc + f36ca26 commit f3a75a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SecurityCodeScan.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ internal class ParsedOptions
public bool ignoreMsBuildErrors = false;
public bool showBanner = true;
public bool cwe = false;
public bool failOnWarning = false;
public HashSet<string> excludeWarnings = new HashSet<string>();
public HashSet<string> includeWarnings = new HashSet<string>();
public List<Glob> excludeProjects = new List<Glob>();
Expand Down Expand Up @@ -184,6 +185,7 @@ public void Parse(string[] args)
{ "n|no-banner", "(Optional) don't show the banner", r => { showBanner = r == null; } },
{ "v|verbose", "(Optional) more diagnostic messages", r => { verbose = r != null; } },
{ "ignore-msbuild-errors", "(Optional) Don't stop on MSBuild errors", r => { ignoreMsBuildErrors = r != null; } },
{ "f|fail-any-warn","(Optional) fail on any warnings with non-zero exit code", r => { failOnWarning = r != null; } },
{ "h|?|help", "show this message and exit", h => shouldShowHelp = h != null },
};

Expand Down Expand Up @@ -305,6 +307,13 @@ private static async Task<int> Main(string[] args)
Console.WriteLine($@"Completed in {elapsed:hh\:mm\:ss}");
Console.WriteLine($@"{count} warnings");

if (parsedOptions.failOnWarning && count > 0)
{
const int exitCode = 1;
Console.WriteLine($@"Exiting with {exitCode} due to warnings.");
return exitCode;
}

return 0;
}
}
Expand Down

0 comments on commit f3a75a4

Please sign in to comment.