Browse Source

ABP CLI prompt command

Resolve #8886
pull/8906/head
maliming 5 years ago
parent
commit
0d7b50cc17
  1. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
  2. 47
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs
  3. 33
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/PromptCommand.cs

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs

@ -29,6 +29,7 @@ namespace Volo.Abp.Cli
{
//TODO: Define constants like done for GenerateProxyCommand.Name.
options.Commands["help"] = typeof(HelpCommand);
options.Commands["prompt"] = typeof(PromptCommand);
options.Commands["new"] = typeof(NewCommand);
options.Commands["get-source"] = typeof(GetSourceCommand);
options.Commands["update"] = typeof(UpdateCommand);

47
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs

@ -48,10 +48,14 @@ namespace Volo.Abp.Cli
}
#endif
var commandLineArgs = CommandLineArgumentParser.Parse(args);
try
{
if (commandLineArgs.IsCommand("batch"))
if (commandLineArgs.IsCommand("prompt"))
{
await RunPromptAsync();
}
else if (commandLineArgs.IsCommand("batch"))
{
await RunBatchAsync(commandLineArgs);
}
@ -70,6 +74,45 @@ namespace Volo.Abp.Cli
}
}
private async Task RunPromptAsync()
{
string GetPromptInput()
{
Console.WriteLine("Enter the command to execute or `exit` to exit the prompt model");
Console.Write("> ");
return Console.ReadLine();
}
var promptInput = GetPromptInput();
do
{
try
{
var commandLineArgs = CommandLineArgumentParser.Parse(promptInput.Split(" ").Where(x => !x.IsNullOrWhiteSpace()).ToArray());
if (commandLineArgs.IsCommand("batch"))
{
await RunBatchAsync(commandLineArgs);
}
else
{
await RunInternalAsync(commandLineArgs);
}
}
catch (CliUsageException usageException)
{
Logger.LogWarning(usageException.Message);
}
catch (Exception ex)
{
Logger.LogException(ex);
}
promptInput = GetPromptInput();
} while (promptInput?.ToLower() != "exit");
}
private async Task RunBatchAsync(CommandLineArgs commandLineArgs)
{
var targetFile = commandLineArgs.Target;

33
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/PromptCommand.cs

@ -0,0 +1,33 @@
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands
{
public class PromptCommand : IConsoleCommand, ITransientDependency
{
public Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
return Task.CompletedTask;
}
public string GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp prompt");
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 "Starts with prompt mode.";
}
}
}
Loading…
Cancel
Save