Example #1
0
        private static int RunAnalyzeCommand(CLIAnalyzeCmdOptions cliOptions)
        {
            AnalyzeResult.ExitCode exitCode = AnalyzeResult.ExitCode.CriticalError;

            AnalyzeCommand command = new AnalyzeCommand(new AnalyzeOptions()
            {
                SourcePath            = cliOptions.SourcePath ?? "",
                CustomRulesPath       = cliOptions.CustomRulesPath ?? "",
                IgnoreDefaultRules    = cliOptions.IgnoreDefaultRules,
                AllowDupTags          = cliOptions.AllowDupTags,
                ConfidenceFilters     = cliOptions.ConfidenceFilters,
                MatchDepth            = cliOptions.MatchDepth,
                FilePathExclusions    = cliOptions.FilePathExclusions,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log          = cliOptions.Log,
                SingleThread = cliOptions.SingleThread
            });;

            AnalyzeResult analyzeResult = command.GetResult();

            exitCode = analyzeResult.ResultCode;
            ResultsWriter.Write(analyzeResult, cliOptions);

            return((int)exitCode);
        }
Example #2
0
        private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions)
        {
            TagDiffCommand command = new(new TagDiffOptions()
            {
                SourcePath1 = cliOptions.SourcePath1,
                SourcePath2 = cliOptions.SourcePath2,
                CustomRulesPath = cliOptions.CustomRulesPath,
                IgnoreDefaultRules = cliOptions.IgnoreDefaultRules,
                FilePathExclusions = cliOptions.FilePathExclusions,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                TestType = cliOptions.TestType,
                Log = cliOptions.Log,
                ConfidenceFilters = cliOptions.ConfidenceFilters,
                FileTimeOut = cliOptions.FileTimeOut,
                ProcessingTimeOut = cliOptions.ProcessingTimeOut,
                ScanUnknownTypes = cliOptions.ScanUnknownTypes,
                SingleThread = cliOptions.SingleThread,
                LogFilePath = cliOptions.LogFilePath,
                LogFileLevel = cliOptions.LogFileLevel
            });

            TagDiffResult tagDiffResult = command.GetResult();

            ResultsWriter.Write(tagDiffResult, cliOptions);

            return((int)tagDiffResult.ResultCode);
        }
Example #3
0
        private static int RunExportTagsCommand(CLIExportTagsCmdOptions cliOptions)
        {
            ExportTagsCommand command = new(new ExportTagsOptions()
            {
                IgnoreDefaultRules = cliOptions.IgnoreDefaultRules,
                CustomRulesPath = cliOptions.CustomRulesPath,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log
            });

            ExportTagsResult exportTagsResult = command.GetResult();

            ResultsWriter.Write(exportTagsResult, cliOptions);

            return((int)exportTagsResult.ResultCode);
        }
Example #4
0
        private static int RunPackRulesCommand(CLIPackRulesCmdOptions cliOptions)
        {
            PackRulesCommand command = new(new PackRulesOptions()
            {
                RepackDefaultRules = cliOptions.RepackDefaultRules,
                CustomRulesPath = cliOptions.CustomRulesPath,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log,
                PackEmbeddedRules = cliOptions.PackEmbeddedRules
            });

            PackRulesResult exportTagsResult = command.GetResult();

            ResultsWriter.Write(exportTagsResult, cliOptions);

            return((int)exportTagsResult.ResultCode);
        }
Example #5
0
        private static int RunVerifyRulesCommand(CLIVerifyRulesCmdOptions cliOptions)
        {
            VerifyRulesCommand command = new(new VerifyRulesOptions()
            {
                VerifyDefaultRules = cliOptions.VerifyDefaultRules,
                CustomRulesPath = cliOptions.CustomRulesPath,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Failfast = cliOptions.Failfast,
                Log = cliOptions.Log
            });

            VerifyRulesResult exportTagsResult = command.GetResult();

            ResultsWriter.Write(exportTagsResult, cliOptions);

            return((int)exportTagsResult.ResultCode);
        }
Example #6
0
        private static int RunPackRulesCommand(CLIPackRulesCmdOptions cliOptions)
        {
            PackRulesResult.ExitCode exitCode = PackRulesResult.ExitCode.CriticalError;

            PackRulesCommand command = new PackRulesCommand(new PackRulesOptions()
            {
                RepackDefaultRules    = cliOptions.RepackDefaultRules,
                CustomRulesPath       = cliOptions.CustomRulesPath,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log
            });

            PackRulesResult exportTagsResult = command.GetResult();

            exitCode = exportTagsResult.ResultCode;
            ResultsWriter.Write(exportTagsResult, cliOptions);

            return((int)exitCode);
        }
Example #7
0
        private static int RunTagTestCommand(CLITagTestCmdOptions cliOptions)
        {
            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;

            TagTestCommand command = new TagTestCommand(new TagTestOptions()
            {
                SourcePath            = cliOptions.SourcePath,
                CustomRulesPath       = cliOptions.CustomRulesPath,
                FilePathExclusions    = cliOptions.FilePathExclusions,
                TestType              = cliOptions.TestType,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log
            });

            TagTestResult tagTestCommand = command.GetResult();

            exitCode = tagTestCommand.ResultCode;
            ResultsWriter.Write(tagTestCommand, cliOptions);

            return((int)exitCode);
        }
Example #8
0
        private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions)
        {
            TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError;

            TagDiffCommand command = new TagDiffCommand(new TagDiffOptions()
            {
                SourcePath1           = cliOptions.SourcePath1 ?? "",
                SourcePath2           = cliOptions.SourcePath2 ?? "",
                CustomRulesPath       = cliOptions.CustomRulesPath,
                IgnoreDefaultRules    = cliOptions.IgnoreDefaultRules,
                FilePathExclusions    = cliOptions.FilePathExclusions,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                TestType = cliOptions.TestType,
                Log      = cliOptions.Log
            });

            TagDiffResult tagDiffResult = command.GetResult();

            exitCode = tagDiffResult.ResultCode;
            ResultsWriter.Write(tagDiffResult, cliOptions);

            return((int)exitCode);
        }
Example #9
0
        private static int RunAnalyzeCommand(CLIAnalyzeCmdOptions cliOptions)
        {
            // If the user manually specified -1 this means they also don't even want the snippet in sarif, so we respect that option
            // Otherwise if we are outputting sarif we don't use any of the context information so we set context to 0, if not sarif leave it alone.
            bool isSarif         = cliOptions.OutputFileFormat.Equals("sarif", StringComparison.InvariantCultureIgnoreCase);
            int  numContextLines = cliOptions.ContextLines == -1 ? cliOptions.ContextLines : isSarif ? 0 : cliOptions.ContextLines;
            // tagsOnly isn't compatible with sarif output, we choose to prioritize the choice of sarif.
            bool           tagsOnly = !isSarif && cliOptions.TagsOnly;
            AnalyzeCommand command  = new(new AnalyzeOptions()
            {
                SourcePath = cliOptions.SourcePath ?? Array.Empty <string>(),
                CustomRulesPath = cliOptions.CustomRulesPath ?? "",
                IgnoreDefaultRules = cliOptions.IgnoreDefaultRules,
                ConfidenceFilters = cliOptions.ConfidenceFilters,
                FilePathExclusions = cliOptions.FilePathExclusions,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log,
                SingleThread = cliOptions.SingleThread,
                NoShowProgress = cliOptions.NoShowProgressBar,
                FileTimeOut = cliOptions.FileTimeOut,
                ProcessingTimeOut = cliOptions.ProcessingTimeOut,
                ContextLines = numContextLines,
                ScanUnknownTypes = cliOptions.ScanUnknownTypes,
                TagsOnly = tagsOnly,
                NoFileMetadata = cliOptions.NoFileMetadata,
                AllowAllTagsInBuildFiles = cliOptions.AllowAllTagsInBuildFiles,
                MaxNumMatchesPerTag = cliOptions.MaxNumMatchesPerTag
            });

            if (!cliOptions.NoShowProgressBar)
            {
                WriteOnce.PauseConsoleOutput = true;
            }

            AnalyzeResult analyzeResult = command.GetResult();

            if (cliOptions.NoShowProgressBar)
            {
                ResultsWriter.Write(analyzeResult, cliOptions);
            }
            else
            {
                var done = false;

                _ = Task.Factory.StartNew(() =>
                {
                    ResultsWriter.Write(analyzeResult, cliOptions);
                    done = true;
                });

                var options = new ProgressBarOptions
                {
                    ForegroundColor         = ConsoleColor.Yellow,
                    ForegroundColorDone     = ConsoleColor.DarkGreen,
                    BackgroundColor         = ConsoleColor.DarkGray,
                    BackgroundCharacter     = '\u2593',
                    DisableBottomPercentage = true
                };

                using (var pbar = new IndeterminateProgressBar("Writing Result Files.", options))
                {
                    while (!done)
                    {
                        Thread.Sleep(100);
                    }
                    pbar.Message = "Results written.";

                    pbar.Finished();
                }
                Console.Write(Environment.NewLine);
            }

            WriteOnce.PauseConsoleOutput = false;

            return((int)analyzeResult.ResultCode);
        }