From 24514b0703ebf6efacc8d7aab9aa7189223b2a32 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 11 Mar 2025 15:48:34 +0300 Subject: [PATCH 1/2] Cli: provided a way to hide commands from command list --- .../Commands/CreateMigrationAndRunMigratorCommand.cs | 2 ++ .../Volo/Abp/Cli/Commands/HelpCommand.cs | 12 ++++++++++-- .../Abp/Cli/Commands/Internal/HideFromCommandList.cs | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/HideFromCommandList.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs index fcdbe094aa..b8b6a02d72 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs @@ -5,12 +5,14 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Commands.Internal; using Volo.Abp.Cli.Commands.Services; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands; +[HideFromCommandList] public class CreateMigrationAndRunMigratorCommand : IConsoleCommand, ITransientDependency { private readonly InitialMigrationCreator _initialMigrationCreator; 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 5b6c80d3be..9fb647806b 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,4 +1,6 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -7,6 +9,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Volo.Abp.Cli.Args; +using Volo.Abp.Cli.Commands.Internal; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands; @@ -65,7 +68,7 @@ public class HelpCommand : IConsoleCommand, ITransientDependency sb.AppendLine("Command List:"); sb.AppendLine(""); - foreach (var command in AbpCliOptions.Commands.ToArray()) + foreach (var command in AbpCliOptions.Commands.ToArray().Where(NotHiddenFromCommandList)) { var method = command.Value.GetMethod("GetShortDescription", BindingFlags.Static | BindingFlags.Public); if (method == null) @@ -92,6 +95,11 @@ public class HelpCommand : IConsoleCommand, ITransientDependency return sb.ToString(); } + private bool NotHiddenFromCommandList(KeyValuePair command) + { + return command.Value.GetCustomAttribute(typeof(HideFromCommandList)) == null; + } + public static string GetShortDescription() { return "Show command line help. Write ` abp help `"; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/HideFromCommandList.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/HideFromCommandList.cs new file mode 100644 index 0000000000..9660223a96 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/HideFromCommandList.cs @@ -0,0 +1,6 @@ +using System; + +namespace Volo.Abp.Cli.Commands.Internal; + +public class HideFromCommandList : Attribute +{} \ No newline at end of file From 2276715750abe77822c92aaaa89cab7a56276e7e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 12 Mar 2025 09:39:57 +0300 Subject: [PATCH 2/2] Update RecreateInitialMigrationCommand.cs --- .../Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs index 47c1ac78f4..857edf6bd7 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs @@ -9,6 +9,7 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.Commands.Internal; +[HideFromCommandList] public class RecreateInitialMigrationCommand : IConsoleCommand, ITransientDependency { public const string Name = "recreate-initial-migration";