Esempio n. 1
0
        public static Command Create(HttpClient httpClient)
        {
            var command = new Command(
                name: "refresh",
                description: CoreStrings.RefreshCommandDescription);

            var projectOption = CommonOptions.ProjectOption();
            var dryRunOption  = new Option <bool>(
                aliases: new[] { "--dry-run" },
                description: CoreStrings.DryRunOptionDescription
                );
            var referencesArgument = new Argument <string[]>
            {
                Name        = "references",
                Description = CoreStrings.RefreshCommandArgumentDescription,
                Arity       = ArgumentArity.ZeroOrMore
            };

            command.AddOption(projectOption);
            command.AddOption(dryRunOption);
            command.AddArgument(referencesArgument);

            command.SetHandler <string, bool, string[], InvocationContext, IConsole>(
                async(project, dryRun, references, context, console) =>
            {
                try
                {
                    var command = new RefreshCommand(console, project, httpClient);
                    await command.RefreshAsync(dryRun, references);

                    context.ExitCode = 0;
                }
                catch (CLIToolException e)
                {
                    console.LogError(e);

                    context.ExitCode = -1;
                }
            }, projectOption, dryRunOption, referencesArgument);

            return(command);
        }
Esempio n. 2
0
        public static Command Create()
        {
            var command = new Command(
                name: "refresh",
                description: CoreStrings.RefreshCommandDescription,
                argument: new Argument <string[]>
            {
                Name        = "references",
                Description = CoreStrings.RefreshCommandArgumentDescription,
                Arity       = ArgumentArity.ZeroOrMore
            });

            command.AddOption(CommonOptions.ProjectOption());
            command.AddOption(new Option(
                                  aliases: new[] { "--dry-run" },
                                  description: CoreStrings.DryRunOptionDescription,
                                  argument: Argument.None
                                  ));

            command.Handler = CommandHandler.Create <IConsole, FileInfo, bool, string[]>(
                async(console, project, dryRun, references) =>
            {
                try
                {
                    var command = new RefreshCommand(console, project);
                    await command.RefreshAsync(dryRun, references);

                    return(0);
                }
                catch (CLIToolException e)
                {
                    console.LogError(e);

                    return(-1);
                }
            });

            return(command);
        }