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();
        }
예제 #2
0
        public int RunCommand(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var parser = Parser.Instance;

            ParseResult = parser.ParseFrom($"dotnet {CommandName}", args);

            ParseResult.ShowHelpIfRequested();

            var subcommandName = ParseResult.Command().Name;

            try
            {
                var create = SubCommands[subcommandName];

                var command = create(ParseResult["dotnet"][CommandName]);

                return(command.Execute());
            }
            catch (KeyNotFoundException)
            {
                return(ReportError(CommonLocalizableStrings.RequiredCommandNotPassed));
            }
            catch (GracefulException e)
            {
                return(ReportError(e.Message));
            }
        }
예제 #3
0
 private void ShowHelpIfRequested()
 {
     // This checks for the help option only on the top-level command
     if (ParseResult["dotnet"][CommandName].IsHelpRequested())
     {
         throw new HelpException(ParseResult.Command().HelpView().TrimEnd());
     }
 }
예제 #4
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());
     }
 }
예제 #5
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());
            }
        }
예제 #6
0
        public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult)
        {
            parseResult.ShowHelpIfRequested();

            if (parseResult.Errors.Any())
            {
                throw new CommandParsingException(
                          string.Join(Environment.NewLine,
                                      parseResult.Errors.Select(e => e.Message)),
                          parseResult.Command()?.HelpView().TrimEnd());
            }
        }
예제 #7
0
        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());
            }
        }
예제 #8
0
        public static void ApplyVerbosity(ParseResult result, AppliedOption globalOptions)
        {
            var verbosityValue = globalOptions.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());
            }
        }
예제 #9
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);
        }
예제 #10
0
 public static void ShowHelp(this ParseResult parseResult) =>
 Console.WriteLine(parseResult.Command().HelpView().TrimEnd());