public ListProjectToProjectReferencesCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult) : base()
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }
            if (parseResult == null)
            {
                throw new ArgumentNullException(nameof(parseResult));
            }

            // If showing help, replace the parent's argument rule so that this command's argument
            // only shows `PROJECT` instead of `PROJECT | SOLUTION`.
            if (parseResult.AppliedCommand().IsHelpRequested() &&
                (parseResult.Command().Parent is ListCommandParser.ListCommand parent))
            {
                parent.SetArgumentsRule(
                    Accept.ZeroOrOneArgument()
                    .With(
                        name: CommonLocalizableStrings.ProjectArgumentName,
                        description: CommonLocalizableStrings.ProjectArgumentDescription)
                    .DefaultToCurrentDirectory()
                    );
            }

            ShowHelpOrErrorIfAppropriate(parseResult);

            _fileOrDirectory = appliedCommand.Arguments.Single();
        }
Beispiel #2
0
 public static void ShowHelpIfRequested(this ParseResult parseResult)
 {
     if (parseResult.AppliedCommand().IsHelpRequested())
     {
         // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
         throw new HelpException(parseResult.Command().HelpView().TrimEnd());
     }
 }
Beispiel #3
0
        private static void ShowHelpIfRequested(this ParseResult parseResult)
        {
            var appliedCommand = parseResult.AppliedCommand();

            if (appliedCommand.HasOption("help") ||
                appliedCommand.Arguments.Contains("-?") ||
                appliedCommand.Arguments.Contains("/?"))
            {
                throw new HelpException(parseResult.Command().HelpView().TrimEnd());
            }
        }
        public static void ShowHelpIfRequested(this ParseResult parseResult)
        {
            var appliedCommand = parseResult.AppliedCommand();

            if (appliedCommand.HasOption("help") ||
                appliedCommand.Arguments.Contains("-?") ||
                appliedCommand.Arguments.Contains("/?"))
            {
                // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
                throw new HelpException(parseResult.Command().HelpView().TrimEnd());
            }
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }