Ejemplo n.º 1
0
        private static async Task <int> FixAsync(FixCommandLineOptions options)
        {
            if (!options.TryParseDiagnosticSeverity(CodeFixerOptions.Default.SeverityLevel, out DiagnosticSeverity severityLevel))
            {
                return(1);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixMap, out List <KeyValuePair <string, string> > diagnosticFixMap))
            {
                return(1);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixerMap, out List <KeyValuePair <string, string> > diagnosticFixerMap))
            {
                return(1);
            }

            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(1);
            }

            var command = new FixCommand(
                options: options,
                severityLevel: severityLevel,
                diagnosticFixMap: diagnosticFixMap,
                diagnosticFixerMap: diagnosticFixerMap,
                projectFilter: projectFilter);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result.Kind == CommandResultKind.Success) ? 0 : 1);
        }
Ejemplo n.º 2
0
        private static async Task <int> FixAsync(FixCommandLineOptions options)
        {
            if (!options.TryGetDiagnosticSeverity(CodeFixerOptions.Default.SeverityLevel, out DiagnosticSeverity severityLevel))
            {
                return(1);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixMap, out Dictionary <string, string> diagnosticFixMap))
            {
                return(1);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixerMap, out Dictionary <string, string> diagnosticFixerMap))
            {
                return(1);
            }

            if (!options.TryGetLanguage(out string language))
            {
                return(1);
            }

            var command = new FixCommand(
                options: options,
                severityLevel: severityLevel,
                diagnosticFixMap: diagnosticFixMap?.ToImmutableDictionary() ?? ImmutableDictionary <string, string> .Empty,
                diagnosticFixerMap: diagnosticFixerMap?.ToImmutableDictionary() ?? ImmutableDictionary <string, string> .Empty,
                language: language);

            CommandResult result = await command.ExecuteAsync(options.Path, options.MSBuildPath, options.Properties);

            return((result.Kind == CommandResultKind.Success) ? 0 : 1);
        }
Ejemplo n.º 3
0
        private static async Task <int> FixAsync(FixCommandLineOptions options)
        {
            if (!options.TryParseDiagnosticSeverity(CodeFixerOptions.Default.SeverityLevel, out DiagnosticSeverity severityLevel))
            {
                return(ExitCodes.Error);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixMap, out List <KeyValuePair <string, string> > diagnosticFixMap))
            {
                return(ExitCodes.Error);
            }

            if (!TryParseKeyValuePairs(options.DiagnosticFixerMap, out List <KeyValuePair <string, string> > diagnosticFixerMap))
            {
                return(ExitCodes.Error);
            }

            if (!TryParseOptionValueAsEnum(options.FixScope, OptionNames.FixScope, out FixAllScope fixAllScope, FixAllScope.Project))
            {
                return(ExitCodes.Error);
            }

            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(ExitCodes.Error);
            }

            if (!TryParsePaths(options.Paths, out ImmutableArray <string> paths))
            {
                return(ExitCodes.Error);
            }

            var command = new FixCommand(
                options: options,
                severityLevel: severityLevel,
                diagnosticFixMap: diagnosticFixMap,
                diagnosticFixerMap: diagnosticFixerMap,
                fixAllScope: fixAllScope,
                projectFilter: projectFilter);

            CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties);

            return(GetExitCode(status));
        }