예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public static Command Create(HttpClient httpClient)
        {
            var command = new Command(
                name: "add-file",
                description: CoreStrings.AddFileCommandDescription);

            var projectOption = CommonOptions.ProjectOption();
            var serviceOption = CommonOptions.ServiceOption();
            var additionalImportDirsOption = CommonOptions.AdditionalImportDirsOption();
            var accessOption  = CommonOptions.AccessOption();
            var filesArgument = new Argument <string[]>
            {
                Name        = "files",
                Description = CoreStrings.AddFileCommandArgumentDescription,
                Arity       = ArgumentArity.OneOrMore
            };

            command.AddOption(projectOption);
            command.AddOption(serviceOption);
            command.AddOption(accessOption);
            command.AddOption(additionalImportDirsOption);
            command.AddArgument(filesArgument);

            command.SetHandler <string, Services, Access, string?, string[], InvocationContext, IConsole>(
                async(project, services, access, additionalImportDirs, files, context, console) =>
            {
                try
                {
                    var command = new AddFileCommand(console, project, httpClient);
                    await command.AddFileAsync(services, access, additionalImportDirs, files);

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

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

            return(command);
        }
예제 #4
0
        public static Command Create()
        {
            var command = new Command(
                name: "add-file",
                description: CoreStrings.AddFileCommandDescription);

            command.AddArgument(new Argument <string[]>
            {
                Name        = "files",
                Description = CoreStrings.AddFileCommandArgumentDescription,
                Arity       = ArgumentArity.OneOrMore
            });

            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[]>(
                async(console, project, services, access, additionalImportDirs, files) =>
            {
                try
                {
                    var command = new AddFileCommand(console, project);
                    await command.AddFileAsync(services, access, additionalImportDirs, files);

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

                    return(-1);
                }
            });

            return(command);
        }