diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs index 985ca49f17..a43a910340 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs @@ -40,6 +40,37 @@ namespace Volo.Abp.Cli.Commands ); } + public Task GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("'add-module' command is used to add a multi-package ABP module to a solution."); + sb.AppendLine("It should be used in a folder containing a .sln file."); + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp add-module [-s|--solution]"); + sb.AppendLine(""); + sb.AppendLine("Options:"); + sb.AppendLine(" -s|--solution Specify the solution file explicitly."); + sb.AppendLine(" --skip-db-migrations Specify if a new migration will be added or not."); + sb.AppendLine(""); + sb.AppendLine("Examples:"); + sb.AppendLine(" abp add-module Volo.Blogging Adds the module to the current soluton."); + sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore Adds the module to the given soluton."); + sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore --skip-db-migrations false Adds the module to the given soluton but doesn't create a database migration."); + sb.AppendLine(""); + + return Task.FromResult(sb.ToString()); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult("Adds a multi-package module to a solution by finding all packages of the module, " + + "finding related projects in the solution and adding each package to the" + + " corresponding project in the solution."); + } + protected virtual string GetSolutionFile(CommandLineArgs commandLineArgs) { var providedSolutionFile = PathHelper.NormalizePath( @@ -80,30 +111,6 @@ namespace Volo.Abp.Cli.Commands throw new CliUsageException(sb.ToString()); } - protected virtual string GetUsageInfo() - { - var sb = new StringBuilder(); - - sb.AppendLine(""); - sb.AppendLine("'add-module' command is used to add a multi-package ABP module to a solution."); - sb.AppendLine("It should be used in a folder containing a .sln file."); - sb.AppendLine(""); - sb.AppendLine("Usage:"); - sb.AppendLine(" abp add-module [-s|--solution]"); - sb.AppendLine(""); - sb.AppendLine("Options:"); - sb.AppendLine(" -s|--solution Specify the solution file explicitly."); - sb.AppendLine(" --skip-db-migrations Specify if a new migration will be added or not."); - sb.AppendLine(""); - sb.AppendLine("Examples:"); - sb.AppendLine(" abp add-module Volo.Blogging Adds the module to the current soluton."); - sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore Adds the module to the given soluton."); - sb.AppendLine(" abp add-module Volo.Blogging -s Acme.BookStore --skip-db-migrations false Adds the module to the given soluton but doesn't create a database migration."); - sb.AppendLine(""); - - return sb.ToString(); - } - public static class Options { public static class Solution diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs index d657000b2d..24185d7c07 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs @@ -36,6 +36,35 @@ namespace Volo.Abp.Cli.Commands ); } + public Task GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("'add-package' command is used to add an ABP package to a project."); + sb.AppendLine("It should be used in a folder containing a .csproj file."); + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp add-package [-p|--project]"); + sb.AppendLine(""); + sb.AppendLine("Options:"); + sb.AppendLine(" -p|--project Specify the project file explicitly."); + sb.AppendLine(""); + sb.AppendLine("Examples:"); + sb.AppendLine(" abp add-package Volo.Abp.FluentValidation Adds the package to the current project."); + sb.AppendLine(" abp add-package Volo.Abp.FluentValidation -p Acme.BookStore.Application Adds the package to the given project."); + sb.AppendLine(""); + + return Task.FromResult(sb.ToString()); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult("Adds a new ABP package to a project by adding related nuget package" + + " as a dependency to the project and adding [DependsOn(...)] attribute to" + + " the module class in the project."); + } + protected virtual string GetProjectFile(CommandLineArgs commandLineArgs) { var providedProjectFile = PathHelper.NormalizePath( @@ -76,27 +105,6 @@ namespace Volo.Abp.Cli.Commands throw new CliUsageException(sb.ToString()); } - protected virtual string GetUsageInfo() - { - var sb = new StringBuilder(); - - sb.AppendLine(""); - sb.AppendLine("'add-package' command is used to add an ABP package to a project."); - sb.AppendLine("It should be used in a folder containing a .csproj file."); - sb.AppendLine(""); - sb.AppendLine("Usage:"); - sb.AppendLine(" abp add-package [-p|--project]"); - sb.AppendLine(""); - sb.AppendLine("Options:"); - sb.AppendLine(" -p|--project Specify the project file explicitly."); - sb.AppendLine(""); - sb.AppendLine("Examples:"); - sb.AppendLine(" abp add-package Volo.Abp.FluentValidation Adds the package to the current project."); - sb.AppendLine(" abp add-package Volo.Abp.FluentValidation -p Acme.BookStore.Application Adds the package to the given project."); - sb.AppendLine(""); - - return sb.ToString(); - } public static class Options { diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs index 60f64f12a2..fe574c2112 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs @@ -1,5 +1,7 @@ using System.Linq; +using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -12,30 +14,69 @@ namespace Volo.Abp.Cli.Commands { public ILogger Logger { get; set; } protected CliOptions CliOptions { get; } + protected IHybridServiceScopeFactory ServiceScopeFactory { get; } - public HelpCommand(IOptions cliOptions) + public HelpCommand(IOptions cliOptions, + IHybridServiceScopeFactory serviceScopeFactory) { + ServiceScopeFactory = serviceScopeFactory; Logger = NullLogger.Instance; CliOptions = cliOptions.Value; } - public Task ExecuteAsync(CommandLineArgs commandLineArgs) + public async Task ExecuteAsync(CommandLineArgs commandLineArgs) { - Logger.LogInformation(""); - Logger.LogInformation("Usage:"); - Logger.LogInformation(""); - Logger.LogInformation(" abp [options]"); - Logger.LogInformation(""); - Logger.LogInformation("Command List:"); - - foreach (var commandKey in CliOptions.Commands.Keys.ToArray()) + if (string.IsNullOrWhiteSpace(commandLineArgs.Target)) { - Logger.LogInformation(" " + commandKey); + Logger.LogInformation(await GetUsageInfo()); + return; } - Logger.LogInformation(""); + var commandType = CliOptions.Commands[commandLineArgs.Target]; - return Task.CompletedTask; + using (var scope = ServiceScopeFactory.CreateScope()) + { + var command = (IConsoleCommand) scope.ServiceProvider.GetRequiredService(commandType); + Logger.LogInformation(await command.GetUsageInfo()); + } + } + + public async Task GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(""); + sb.AppendLine(" abp [options]"); + sb.AppendLine(""); + sb.AppendLine("Command List:"); + + foreach (var command in CliOptions.Commands.ToArray()) + { + string shortDescription; + + using (var scope = ServiceScopeFactory.CreateScope()) + { + shortDescription = await ((IConsoleCommand)scope.ServiceProvider.GetRequiredService(command.Value)) + .GetShortDescriptionAsync(); + } + + sb.Append(" >"); + sb.Append(command.Key); + sb.Append(string.IsNullOrWhiteSpace(shortDescription) ? "":":"); + sb.Append(" "); + sb.AppendLine(shortDescription); + } + + sb.AppendLine(""); + + return sb.ToString(); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult(""); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs index 2b1129aab2..b9fb34210b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs @@ -6,5 +6,9 @@ namespace Volo.Abp.Cli.Commands public interface IConsoleCommand { Task ExecuteAsync(CommandLineArgs commandLineArgs); + + Task GetUsageInfo(); + + Task GetShortDescriptionAsync(); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs index 28bc64afd5..52517b72fa 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using System; +using System.Text; using System.Threading.Tasks; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Auth; @@ -25,20 +26,14 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target.IsNullOrEmpty()) { - Logger.LogInformation(""); - Logger.LogWarning("Username is missing."); - LogHelp(); - return; + throw new CliUsageException("Username name is missing!" + Environment.NewLine + Environment.NewLine + GetUsageInfo()); } Console.Write("Password: "); var password = ConsoleHelper.ReadSecret(); if (password.IsNullOrWhiteSpace()) { - Logger.LogInformation(""); - Logger.LogWarning("Password is missing."); - LogHelp(); - return; + throw new CliUsageException("Password name is missing!" + Environment.NewLine + Environment.NewLine + GetUsageInfo()); } await AuthService.LoginAsync(commandLineArgs.Target, password); @@ -46,14 +41,23 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation($"Successfully logged in as '{commandLineArgs.Target}'"); } - private void LogHelp() + public Task GetUsageInfo() { - Logger.LogWarning(""); - Logger.LogWarning("Usage:"); - Logger.LogWarning(" abp login "); - Logger.LogWarning(""); - Logger.LogWarning("Example:"); - Logger.LogWarning(" abp login john"); + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp login "); + sb.AppendLine(""); + sb.AppendLine("Example:"); + sb.AppendLine(" abp login john"); + + return Task.FromResult(sb.ToString()); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult(""); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs index 342e52f529..22d30367e6 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs @@ -23,5 +23,15 @@ namespace Volo.Abp.Cli.Commands { return AuthService.LogoutAsync(); } + + public Task GetUsageInfo() + { + return Task.FromResult(""); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult(""); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index 5979348004..44b5416e1e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -1,4 +1,6 @@ +using System; using System.IO; +using System.Text; using System.Threading.Tasks; using Ionic.Zip; using Microsoft.Extensions.Logging; @@ -27,30 +29,7 @@ namespace Volo.Abp.Cli.Commands { if (commandLineArgs.Target == null) { - Logger.LogInformation(""); - Logger.LogWarning("Project name is missing."); - Logger.LogWarning(""); - Logger.LogWarning("Usage:"); - Logger.LogWarning(" abp new [-t|--template] [-d|--database-provider] [-o|--output-folder]"); - Logger.LogWarning(""); - Logger.LogWarning("Options:"); - Logger.LogWarning("-t|--template "); - Logger.LogWarning("-o|--output-folder "); - Logger.LogWarning("-d|--database-provider (if supported by the template)"); - Logger.LogWarning("--tiered (if supported by the template)"); - Logger.LogWarning("--no-ui (if supported by the template)"); - Logger.LogWarning(""); - Logger.LogWarning("Some examples:"); - Logger.LogWarning(" abp new Acme.BookStore"); - Logger.LogWarning(" abp new Acme.BookStore --tiered"); - Logger.LogWarning(" abp new Acme.BookStore -t mvc-module"); - Logger.LogWarning(" abp new Acme.BookStore -t mvc-module no-ui"); - Logger.LogWarning(" abp new Acme.BookStore -d mongodb"); - Logger.LogWarning(" abp new Acme.BookStore -t mvc -d mongodb"); - Logger.LogWarning(" abp new Acme.BookStore -t mvc -d mongodb -o d:\\project"); - Logger.LogWarning(""); - Logger.LogWarning("See the documentation for more info."); - return; + throw new CliUsageException("Project name is missing!" + Environment.NewLine + Environment.NewLine + GetUsageInfo()); } Logger.LogInformation("Creating a new project..."); @@ -92,6 +71,40 @@ namespace Volo.Abp.Cli.Commands Logger.LogInformation($"The output folder is: '{outputFolder}'"); } + public Task GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp new [-t|--template] [-d|--database-provider] [-o|--output-folder]"); + sb.AppendLine(""); + sb.AppendLine("Options:"); + sb.AppendLine("-t|--template "); + sb.AppendLine("-o|--output-folder "); + sb.AppendLine("-d|--database-provider (if supported by the template)"); + sb.AppendLine("--tiered (if supported by the template)"); + sb.AppendLine("--no-ui (if supported by the template)"); + sb.AppendLine(""); + sb.AppendLine("Some examples:"); + sb.AppendLine(" abp new Acme.BookStore"); + sb.AppendLine(" abp new Acme.BookStore --tiered"); + sb.AppendLine(" abp new Acme.BookStore -t mvc-module"); + sb.AppendLine(" abp new Acme.BookStore -t mvc-module no-ui"); + sb.AppendLine(" abp new Acme.BookStore -d mongodb"); + sb.AppendLine(" abp new Acme.BookStore -t mvc -d mongodb"); + sb.AppendLine(" abp new Acme.BookStore -t mvc -d mongodb -o d:\\project"); + sb.AppendLine(""); + sb.AppendLine("See the documentation for more info."); + + return Task.FromResult(sb.ToString()); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult("Generates a new solution based on the ABP startup templates."); + } + protected virtual DatabaseProvider GetDatabaseProviderOrNull(CommandLineArgs commandLineArgs) { var optionValue = commandLineArgs.Options.GetOrNull(Options.DatabaseProvider.Short, Options.DatabaseProvider.Long); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs index 2a3259b4c9..df95839767 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -51,7 +52,33 @@ namespace Volo.Abp.Cli.Commands return; } - Logger.LogError("No solution or project found in this directory."); + throw new CliUsageException("No solution or project found in this directory." + Environment.NewLine + Environment.NewLine + GetUsageInfo()); + } + + public Task GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp update [-p|--include-previews]"); + sb.AppendLine(""); + sb.AppendLine("Options:"); + sb.AppendLine("--include-previews (if supported by the template)"); + sb.AppendLine(""); + sb.AppendLine("Some examples:"); + sb.AppendLine(" abp update"); + sb.AppendLine(" abp update --include-previews"); + sb.AppendLine(""); + sb.AppendLine("See the documentation for more info."); + + return Task.FromResult(sb.ToString()); + } + + public Task GetShortDescriptionAsync() + { + return Task.FromResult("Automatically updates all ABP related packages in a" + + " solution or project to the latest versions."); } public static class Options