Browse Source

Add `CleanCommand`.

Resolve #11011
pull/11019/head
maliming 5 years ago
parent
commit
5ad2c33c5e
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
  2. 62
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs

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

@ -41,8 +41,8 @@ public class AbpCliCoreModule : AbpModule
Configure<AbpCliOptions>(options =>
{
//TODO: Define constants like done for GenerateProxyCommand.Name.
options.Commands["help"] = typeof(HelpCommand);
//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);
@ -64,6 +64,7 @@ public class AbpCliCoreModule : AbpModule
options.Commands["bundle"] = typeof(BundleCommand);
options.Commands["create-migration-and-run-migrator"] = typeof(CreateMigrationAndRunMigratorCommand);
options.Commands["install-libs"] = typeof(InstallLibsCommand);
options.Commands["clean"] = typeof(CleanCommand);
});
Configure<AbpCliServiceProxyOptions>(options =>

62
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanCommand.cs

@ -0,0 +1,62 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands;
public class CleanCommand : IConsoleCommand, ITransientDependency
{
public ILogger<CleanCommand> Logger { get; set; }
public CleanCommand()
{
Logger = NullLogger<CleanCommand>.Instance;
}
public Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
var binEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "bin", SearchOption.AllDirectories);
var objEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "obj", SearchOption.AllDirectories);
foreach (var path in binEntries.Concat(objEntries))
{
if (path.IndexOf("node_modules", StringComparison.OrdinalIgnoreCase) > 0)
{
Logger.LogInformation($"Skipping: {path}");
}
else
{
Logger.LogInformation($"Deleting: {path}");
Directory.Delete(path, true);
}
}
Logger.LogInformation($"BIN and OBJ folders have been successfully deleted!");
return Task.CompletedTask;
}
public string GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp clean");
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 "Delete all BIN and OBJ folders in current folder.";
}
}
Loading…
Cancel
Save