Esempio n. 1
0
        /// <summary>
        /// The entry-point method for this application.
        /// </summary>
        /// <param name="args">
        /// The command line arguments passed to this method.
        /// </param>
        private static void Main(string[] args)
        {
            var options = GetOptions();
            Action<string> debugAction = null;
            try
            {
                opts.Parse(args);
                if (options.WithDebug)
                {
                    debugAction = x => { Console.WriteLine(x); };
                    PrintVersion(debugAction);
                }

                options.Validate();
            }
            catch (OptionException error)
            {
                Console.WriteLine("Invalid arguments");
                Console.WriteLine(error);
                options.NeedHelp = true;
            }

            if (options.NeedHelp)
            {
                PrintUsageAndHelp();
                return;
            }

            var report = new ReportBuilder()
                .WithDedupe(options.Dedupe)
                .WithStyleCopSettingsFile(options.StyleCopSettings)
                .WithRecursion(options.Recurse)
                .WithSolutionsFiles(options.SolutionFiles)
                .WithProjectFiles(options.ProjectFiles)
                .WithDirectories(options.Directories)
                .WithFiles(options.Files)
                .WithIgnorePatterns(options.IgnorePatterns)
                .WithDebug(debugAction)
                .WithAddins(options.Addins)
                .WithProjectUnloads(options.ProjectUnloads)
                .WithProcessorSymbols(options.Symbols);

            foreach (var opt in options.Optionals)
            {
                report = report.AddOptional(opt.Key, opt.Value);
            }

            RunReport(report, options.Generator, options.OutputXml, options.Quiet, options.Violations);
            if (options.MaxViolations.HasValue && violationCount > options.MaxViolations.Value)
            {
                Environment.Exit(1);
            }
        }