Yunus Emre Kalkan 7 years ago
parent
commit
9b1f4f07df
  1. 55
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs
  2. 50
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs
  3. 67
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs
  4. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/IConsoleCommand.cs
  5. 34
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs
  6. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LogoutCommand.cs
  7. 61
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  8. 29
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

55
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs

@ -40,6 +40,37 @@ namespace Volo.Abp.Cli.Commands
);
}
public Task<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 <module-name> [-s|--solution]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine(" -s|--solution <solution-file> Specify the solution file explicitly.");
sb.AppendLine(" --skip-db-migrations <boolean> 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<string> 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 <module-name> [-s|--solution]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine(" -s|--solution <solution-file> Specify the solution file explicitly.");
sb.AppendLine(" --skip-db-migrations <boolean> 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

50
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs

@ -36,6 +36,35 @@ namespace Volo.Abp.Cli.Commands
);
}
public Task<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 <package-name> [-p|--project]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine(" -p|--project <project-file> 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<string> 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 <package-name> [-p|--project]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine(" -p|--project <project-file> 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
{

67
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<HelpCommand> Logger { get; set; }
protected CliOptions CliOptions { get; }
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public HelpCommand(IOptions<CliOptions> cliOptions)
public HelpCommand(IOptions<CliOptions> cliOptions,
IHybridServiceScopeFactory serviceScopeFactory)
{
ServiceScopeFactory = serviceScopeFactory;
Logger = NullLogger<HelpCommand>.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 <command> <target> [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<string> GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine("");
sb.AppendLine(" abp <command> <target> [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<string> GetShortDescriptionAsync()
{
return Task.FromResult("");
}
}
}

4
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<string> GetUsageInfo();
Task<string> GetShortDescriptionAsync();
}
}

34
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<string> GetUsageInfo()
{
Logger.LogWarning("");
Logger.LogWarning("Usage:");
Logger.LogWarning(" abp login <username>");
Logger.LogWarning("");
Logger.LogWarning("Example:");
Logger.LogWarning(" abp login john");
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp login <username>");
sb.AppendLine("");
sb.AppendLine("Example:");
sb.AppendLine(" abp login john");
return Task.FromResult(sb.ToString());
}
public Task<string> GetShortDescriptionAsync()
{
return Task.FromResult("");
}
}
}

10
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<string> GetUsageInfo()
{
return Task.FromResult("");
}
public Task<string> GetShortDescriptionAsync()
{
return Task.FromResult("");
}
}
}

61
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 <project-name> [-t|--template] [-d|--database-provider] [-o|--output-folder]");
Logger.LogWarning("");
Logger.LogWarning("Options:");
Logger.LogWarning("-t|--template <template-name>");
Logger.LogWarning("-o|--output-folder <output-folder>");
Logger.LogWarning("-d|--database-provider <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<string> GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp new <project-name> [-t|--template] [-d|--database-provider] [-o|--output-folder]");
sb.AppendLine("");
sb.AppendLine("Options:");
sb.AppendLine("-t|--template <template-name>");
sb.AppendLine("-o|--output-folder <output-folder>");
sb.AppendLine("-d|--database-provider <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<string> 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);

29
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<string> 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<string> GetShortDescriptionAsync()
{
return Task.FromResult("Automatically updates all ABP related packages in a" +
" solution or project to the latest versions.");
}
public static class Options

Loading…
Cancel
Save