Exemple #1
0
        public static Command Create(HttpClient httpClient)
        {
            var command = new Command(
                name: "add-url",
                description: CoreStrings.AddUrlCommandDescription);

            var projectOption = CommonOptions.ProjectOption();
            var serviceOption = CommonOptions.ServiceOption();
            var additionalImportDirsOption = CommonOptions.AdditionalImportDirsOption();
            var accessOption = CommonOptions.AccessOption();
            var outputOption = new Option <string>(
                aliases: new[] { "-o", "--output" },
                description: CoreStrings.OutputOptionDescription);
            var urlArgument = new Argument <string>
            {
                Name        = "url",
                Description = CoreStrings.AddUrlCommandArgumentDescription,
                Arity       = ArgumentArity.ExactlyOne
            };

            command.AddOption(outputOption);
            command.AddOption(projectOption);
            command.AddOption(serviceOption);
            command.AddOption(additionalImportDirsOption);
            command.AddOption(accessOption);
            command.AddArgument(urlArgument);

            command.SetHandler <string, Services, Access, string?, string, string, InvocationContext, IConsole>(
                async(project, services, access, additionalImportDirs, url, output, context, console) =>
            {
                try
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        throw new CLIToolException(CoreStrings.ErrorNoOutputProvided);
                    }

                    var command = new AddUrlCommand(console, project, httpClient);
                    await command.AddUrlAsync(services, access, additionalImportDirs, url, output);

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

                    context.ExitCode = -1;
                }
            }, projectOption, serviceOption, accessOption, additionalImportDirsOption, urlArgument, outputOption);

            return(command);
        }
Exemple #2
0
        public static Command Create()
        {
            var command = new Command(
                name: "add-url",
                description: CoreStrings.AddUrlCommandDescription);

            command.AddArgument(new Argument <string>
            {
                Name        = "url",
                Description = CoreStrings.AddUrlCommandArgumentDescription,
                Arity       = ArgumentArity.ExactlyOne
            });

            var outputOption = new Option(
                aliases: new[] { "-o", "--output" },
                description: CoreStrings.OutputOptionDescription);

            outputOption.Argument = new Argument <string> {
                Name = "path", Arity = ArgumentArity.ExactlyOne
            };
            command.AddOption(outputOption);
            command.AddOption(CommonOptions.ProjectOption());
            command.AddOption(CommonOptions.ServiceOption());
            command.AddOption(CommonOptions.AdditionalImportDirsOption());
            command.AddOption(CommonOptions.AccessOption());

            command.Handler = CommandHandler.Create <IConsole, FileInfo, Services, Access, string, string, string>(
                async(console, project, services, access, additionalImportDirs, url, output) =>
            {
                try
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        throw new CLIToolException(CoreStrings.ErrorNoOutputProvided);
                    }

                    var command = new AddUrlCommand(console, project);
                    await command.AddUrlAsync(services, access, additionalImportDirs, url, output);

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

                    return(-1);
                }
            });

            return(command);
        }