Set of options that could be provided via command line.
Пример #1
0
        private static Options ParseCommandLineArgs(string[] args)
        {
            var options = new Options();
            bool result = CommandLine.Parser.Default.ParseArguments(args, options);
            if (!result)
            {
                Console.WriteLine(HelpText.AutoBuild(options).ToString());
                return null;
            }

            return options;
        }
        public Configuration(Options options, Assembly analyzer)
        {
            Contract.Requires(options != null);
            Contract.Requires(options.Solution != null);
            Contract.Requires(File.Exists(options.Solution));
            Contract.Requires(!string.IsNullOrEmpty(options.LogFile));
            Contract.Requires(analyzer != null);

            Solution = options.Solution;
            LogFile = options.LogFile;
            RunInfoLevelDiagnostics = options.RunInfoLevelDiagnostics;
            DisabledDiagnostics = (options.DisabledDiagnostics ?? new string[] {}).ToImmutableHashSet();
            Analyzer = analyzer;
        }
Пример #3
0
        private static Configuration ValidateOptions(Options options)
        {
            if (Path.GetExtension(options.Solution) != ".sln")
            {
                WriteError($"'{options.Solution}' is not a valid solution file.");
                return null;
            }

            if (!File.Exists(options.Solution))
            {
                WriteInfo($"Provided solution file ('{options.Solution}') does not exists. ");
                return null;
            }

            if (!string.IsNullOrEmpty(options.LogFile))
            {
                options.LogFile = Path.GetFullPath(options.LogFile);
                WriteInfo($"Log file enabled ('{options.LogFile}')");

                FileUtilities.TryDeleteIfNeeded(options.LogFile);
            }

            if (options.DisabledDiagnostics != null && options.DisabledDiagnostics.Length != 0)
            {
                WriteInfo($"Disabled diagnostics: {string.Join(", ", options.DisabledDiagnostics)}");
            }

            try
            {
                var executablePath = Assembly.GetExecutingAssembly().Location;
                var analyzerFullPath = Path.Combine(Path.GetDirectoryName(executablePath), AnalyzerAssemblyName);
                var analyzer = Assembly.LoadFile(analyzerFullPath);
                return new Configuration(options, analyzer);
            }
            catch (Exception e)
            {
                WriteError($"Failed to load ErrorProne.NET.dll\r\n{e}");
                return null;
            }
        }