Exemplo n.º 1
0
        private static int ProcessArgs(ParseResult result)
        {
            result.ShowHelpOrErrorIfAppropriate();

            var command        = result.AppliedCommand();
            var verbosityValue = result["dotnet-migrate-2017"].ValueOrDefault <string>("verbosity")?.Trim().ToLowerInvariant() ?? "normal";

            switch (verbosityValue)
            {
            case "q":
            case "quiet":
                verbosity.MinimumLevel = LogEventLevel.Fatal + 1;
                break;

            case "m":
            case "minimal":
                verbosity.MinimumLevel = LogEventLevel.Warning;
                break;

            case "n":
            case "normal":
                verbosity.MinimumLevel = LogEventLevel.Information;
                break;

            case "d":
            case "detailed":
                verbosity.MinimumLevel = LogEventLevel.Debug;
                break;

            // ReSharper disable once StringLiteralTypo
            case "diag":
            case "diagnostic":
                verbosity.MinimumLevel = LogEventLevel.Verbose;
                break;

            default:
                throw new CommandParsingException($"Unknown verbosity level '{verbosityValue}'.", result.Command().HelpView().TrimEnd());
            }

            Log.Verbose(result.Diagram());

            var items = command.Value <string[]>();

            var conversionOptions = new ConversionOptions
            {
                ProjectCache = new DefaultProjectCache()
            };

            var frameworks = command.ValueOrDefault <string[]>("target-frameworks");

            if (frameworks != null)
            {
                conversionOptions.TargetFrameworks = frameworks;
            }

            var logic = new CommandLogic();

            switch (command.Name)
            {
            case "evaluate":
                logic.ExecuteEvaluate(items, conversionOptions);
                break;

            case "migrate":
                conversionOptions.AppendTargetFrameworkToOutputPath =
                    !command.ValueOrDefault <bool>("old-output-path");
                conversionOptions.KeepAssemblyInfo = command.ValueOrDefault <bool>("keep-assembly-info");

                logic.ExecuteMigrate(items, command.ValueOrDefault <bool>("no-backup"), conversionOptions);
                break;

            case "analyze":
                logic.ExecuteAnalyze(items, conversionOptions);
                break;
            }

            return(result.Execute().Code);
        }
Exemplo n.º 2
0
        private static int ProcessArgs(ParseResult result)
        {
            result.ShowHelpOrErrorIfAppropriate();

            var command       = result.AppliedCommand();
            var globalOptions = result["dotnet-migrate-2017"];

            ProgramBase.ApplyVerbosity(result, globalOptions);

            Log.Verbose(result.Diagram());

            var items = command.Value <string[]>();

            var conversionOptions = new ConversionOptions
            {
                ProjectCache = new DefaultProjectCache(),
                ForceOnUnsupportedProjects = command.ValueOrDefault <bool>("force"),
                KeepAssemblyInfo           = command.ValueOrDefault <bool>("keep-assembly-info")
            };

            switch (command.Name)
            {
            case "evaluate":
            case "migrate":
                var frameworks = command.ValueOrDefault <string[]>("target-frameworks");
                if (frameworks != null)
                {
                    conversionOptions.TargetFrameworks = frameworks;
                }
                break;
            }

            var logic = new CommandLogic();

            switch (command.Name)
            {
            case "wizard":
                var diagnostics = new DiagnosticSet(Vs15DiagnosticSet.All);
                diagnostics.ExceptWith(DiagnosticSet.All);
                var sets = new WizardTransformationSets
                {
                    MigrateSet = new ChainTransformationSet(
                        new BasicSimplifyTransformationSet(Vs15TransformationSet.TargetVisualStudioVersion),
                        Vs15TransformationSet.TrueInstance),
                    ModernCleanUpSet = new BasicSimplifyTransformationSet(
                        Vs15TransformationSet.TargetVisualStudioVersion),
                    ModernizeSet = new ChainTransformationSet(
                        new BasicSimplifyTransformationSet(Vs15TransformationSet.TargetVisualStudioVersion),
                        Vs15ModernizationTransformationSet.TrueInstance),
                    Diagnostics = diagnostics
                };

                logic.ExecuteWizard(items, conversionOptions, sets);
                break;

            case "evaluate":
                logic.ExecuteEvaluate(items, conversionOptions, Vs15TransformationSet.Instance, new AnalysisOptions(Vs15DiagnosticSet.All));
                break;

            case "analyze":
                logic.ExecuteAnalyze(items, conversionOptions, new AnalysisOptions(Vs15DiagnosticSet.All));
                break;

            case "migrate":
                conversionOptions.AppendTargetFrameworkToOutputPath = !command.ValueOrDefault <bool>("old-output-path");

                var forceTransformations = command.ValueOrDefault <string[]>("force-transformations");
                if (forceTransformations != null)
                {
                    conversionOptions.ForceDefaultTransforms = forceTransformations;
                }

                logic.ExecuteMigrate(items, command.ValueOrDefault <bool>("no-backup"), conversionOptions, Vs15TransformationSet.Instance);
                break;
            }

            return(result.Execute().Code);
        }