Beispiel #1
0
        static void Main(string[] args)
        {
            var options = new Options();

            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(args, options))
            {
                Environment.Exit(1);
            }

            if (!_reporterMap.ContainsKey(options.Report))
            {
                options.Report = "table";
            }

            if (!_adapterMap.ContainsKey(options.Adapter))
            {
                Console.Error.WriteLine(string.Format("Warning: {0} does not exist.", options.Adapter));
                options.Adapter = "auto";
            }

            try
            {
                //
                // set up cutoff
                //

                IProcessor <KeyValuePair <string, int> > cutoffPolicy = new MinimalCutoffProcessor(0);
                int minchurn;
                if (int.TryParse(options.MinimalChurnRate, out minchurn))
                {
                    cutoffPolicy = new MinimalCutoffProcessor(minchurn);
                }
                else
                {
                    float minchurnpcent;
                    if (float.TryParse(options.MinimalChurnRate, out minchurnpcent))
                    {
                        cutoffPolicy = new PrecentCutoffProcessor(minchurnpcent);
                    }
                }

                //
                // set up analyzer
                //
                Analyzer analyzer = Analyzer.Create(_adapterMap[options.Adapter](options.EnvPath));

                if (!string.IsNullOrEmpty(options.IncludePattern))
                {
                    analyzer.AddInclude(options.IncludePattern);
                }
                if (!string.IsNullOrEmpty(options.ExcludePattern))
                {
                    analyzer.AddExclude(options.ExcludePattern);
                }

                if (options.InputFile != null && !File.Exists(options.InputFile))
                {
                    Console.Error.WriteLine(string.Format("Cannot file file {0} to read from.", options.InputFile));
                    ExitWithError();
                }



                //
                // perform analysis
                //

                AnalysisResult analysisResult;
                if (options.InputFile != null)
                {
                    analysisResult = analyzer.Analyze(File.ReadAllText(options.InputFile));
                }
                else
                {
                    analysisResult = string.IsNullOrEmpty(options.Date) ? analyzer.Analyze()
                                                                        : GetAnalysisResultWithDateBackAnalysis(options, analyzer);
                }

                Console.OutputEncoding = Encoding.UTF8;
                var reporter = _reporterMap[options.Report](Console.Out);
                reporter.Write(analysisResult, cutoffPolicy, options.Top);
            }
            catch (CommandRunnerException e)
            {
                Console.Error.WriteLine(string.Format("Error: {0}. You should make sure that your versioning tool is accessible via command line (set PATH).", e.Message));
                ExitWithError();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(string.Format("Error: {0}.", e.Message));
                ExitWithError();
            }
        }