From d84130012fadf60e0688708d9f579eda1729bdc3 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 22 Jun 2022 09:45:53 +0300 Subject: [PATCH 1/4] Created ListTemplatesCommand empty --- .../Volo/Abp/Cli/AbpCliCoreModule.cs | 1 + .../Abp/Cli/Commands/ListTemplatesCommand.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs index 4fda075521..7aba9ae849 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs @@ -49,6 +49,7 @@ public class AbpCliCoreModule : AbpModule options.Commands[AddPackageCommand.Name] = typeof(AddPackageCommand); options.Commands[AddModuleCommand.Name] = typeof(AddModuleCommand); options.Commands[ListModulesCommand.Name] = typeof(ListModulesCommand); + options.Commands[ListTemplatesCommand.Name] = typeof(ListTemplatesCommand); options.Commands[LoginCommand.Name] = typeof(LoginCommand); options.Commands[LoginInfoCommand.Name] = typeof(LoginInfoCommand); options.Commands[LogoutCommand.Name] = typeof(LogoutCommand); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs new file mode 100644 index 0000000000..c38f55a5b3 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs @@ -0,0 +1,39 @@ +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Cli.Args; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Commands; + +public class ListTemplatesCommand : IConsoleCommand, ITransientDependency +{ + public const string Name = "list-templates"; + + public ListTemplatesCommand() + { + + } + + public async Task ExecuteAsync(CommandLineArgs commandLineArgs) + { + + } + + public string GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp list-templates"); + sb.AppendLine(""); + sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); + + return sb.ToString(); + } + + public string GetShortDescription() + { + return "Lists available templates to be created."; + } +} From 6c3fa717877abca5b97b99460a17019ad7ed610b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 22 Jun 2022 11:10:50 +0300 Subject: [PATCH 2/4] Cli ListTemplatesCommand: Get templates from abp.io & list resolves https://github.com/abpframework/abp/issues/13008 --- .../Abp/Cli/Commands/ListTemplatesCommand.cs | 79 +++++++++++++++++-- .../Cli/Commands/Templates/TemplateInfo.cs | 14 ++++ 2 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Templates/TemplateInfo.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs index c38f55a5b3..7274fb641d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ListTemplatesCommand.cs @@ -1,22 +1,89 @@ -using System.Text; +using System; +using System.Collections.Generic; +using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Commands.Templates; +using Volo.Abp.Cli.Http; +using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.DependencyInjection; +using Volo.Abp.Json; +using Volo.Abp.Threading; namespace Volo.Abp.Cli.Commands; public class ListTemplatesCommand : IConsoleCommand, ITransientDependency { public const string Name = "list-templates"; - - public ListTemplatesCommand() + + private readonly CliHttpClientFactory _cliHttpClientFactory; + private readonly IJsonSerializer _jsonSerializer; + private readonly ICancellationTokenProvider _cancellationTokenProvider; + private readonly IRemoteServiceExceptionHandler _remoteServiceExceptionHandler; + + public ILogger Logger { get; set; } + + public ListTemplatesCommand( + CliHttpClientFactory cliHttpClientFactory, + IJsonSerializer jsonSerializer, + ICancellationTokenProvider cancellationTokenProvider, + IRemoteServiceExceptionHandler remoteServiceExceptionHandler) { - + _cliHttpClientFactory = cliHttpClientFactory; + _jsonSerializer = jsonSerializer; + _cancellationTokenProvider = cancellationTokenProvider; + _remoteServiceExceptionHandler = remoteServiceExceptionHandler; + + Logger = NullLogger.Instance; } public async Task ExecuteAsync(CommandLineArgs commandLineArgs) { - + var templateNameSpaceLength = 26; + var templateDisplayNameSpaceLength = 32; + + var templates = await GetTemplatesAsync(); + + var output = new StringBuilder(Environment.NewLine + Environment.NewLine); + + output.AppendLine( + $"{"Template".PadRight(templateNameSpaceLength)}" + + $"{"Template Name".PadRight(templateDisplayNameSpaceLength)}" + + "Document Url"); + + output.AppendLine( + $"{"--------".PadRight(templateNameSpaceLength)}" + + $"{"-------------".PadRight(templateDisplayNameSpaceLength)}" + + "------------"); + + output.AppendLine(); + + foreach (var template in templates) + { + output.AppendLine( + $"{template.Name?.PadRight(templateNameSpaceLength)}" + + $"{template.DisplayName?.PadRight(templateDisplayNameSpaceLength)}" + + $"{template.DocumentUrl}"); + } + + Logger.LogInformation(output.ToString()); + } + + private async Task> GetTemplatesAsync() + { + var client = _cliHttpClientFactory.CreateClient(); + + using (var responseMessage = await client.GetAsync( + $"{CliUrls.WwwAbpIo}api/download/templates/", + _cancellationTokenProvider.Token + )) + { + await _remoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); + var result = await responseMessage.Content.ReadAsStringAsync(); + return _jsonSerializer.Deserialize>(result); + } } public string GetUsageInfo() @@ -36,4 +103,4 @@ public class ListTemplatesCommand : IConsoleCommand, ITransientDependency { return "Lists available templates to be created."; } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Templates/TemplateInfo.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Templates/TemplateInfo.cs new file mode 100644 index 0000000000..c0c269de5b --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Templates/TemplateInfo.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.Cli.Commands.Templates; + +public class TemplateInfo +{ + public string Name { get; set; } + + public string DisplayName { get; set; } + + public string ShortDescription { get; set; } + + public string DocumentUrl { get; set; } + + public bool IsPro { get; set; } +} \ No newline at end of file From b7a66e54e857dc9ffb7ae5eb0496c1d9e04db404 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 22 Jun 2022 11:14:28 +0300 Subject: [PATCH 3/4] Add `list-templates` to docs https://github.com/abpframework/abp/issues/13008 --- docs/en/CLI.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 57e27c23ec..8f6eaddd9c 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -34,6 +34,7 @@ Here, is the list of all available commands before explaining their details: * **`add-package`**: Adds an ABP package to a project. * **`add-module`**: Adds a [multi-package application module](https://docs.abp.io/en/abp/latest/Modules/Index) to a solution. * **`list-modules`**: Lists names of open-source application modules. +* **`list-templates`**: Lists names of available templates to create solutions. * **`get-source`**: Downloads the source code of a module. * **`generate-proxy`**: Generates client side proxies to use HTTP API endpoints. * **`remove-proxy`**: Removes previously generated client side proxies. From cdd9169ba16a5383c52029cba4ca95300fee1041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alper=20Ebi=C3=A7o=C4=9Flu?= <9526587+ebicoglu@users.noreply.github.com> Date: Thu, 23 Jun 2022 16:57:58 +0300 Subject: [PATCH 4/4] Update CLI.md --- docs/en/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 8f6eaddd9c..408064205a 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -34,7 +34,7 @@ Here, is the list of all available commands before explaining their details: * **`add-package`**: Adds an ABP package to a project. * **`add-module`**: Adds a [multi-package application module](https://docs.abp.io/en/abp/latest/Modules/Index) to a solution. * **`list-modules`**: Lists names of open-source application modules. -* **`list-templates`**: Lists names of available templates to create solutions. +* **`list-templates`**: Lists the names of available templates to create a solution. * **`get-source`**: Downloads the source code of a module. * **`generate-proxy`**: Generates client side proxies to use HTTP API endpoints. * **`remove-proxy`**: Removes previously generated client side proxies.