Browse Source

Cli: provided a way to hide commands from command list

pull/22338/head
Yunus Emre Kalkan 2 years ago
parent
commit
24514b0703
  1. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs
  2. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs
  3. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/HideFromCommandList.cs

2
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;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands.Internal;
using Volo.Abp.Cli.Commands.Services; using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands; namespace Volo.Abp.Cli.Commands;
[HideFromCommandList]
public class CreateMigrationAndRunMigratorCommand : IConsoleCommand, ITransientDependency public class CreateMigrationAndRunMigratorCommand : IConsoleCommand, ITransientDependency
{ {
private readonly InitialMigrationCreator _initialMigrationCreator; private readonly InitialMigrationCreator _initialMigrationCreator;

12
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.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -7,6 +9,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands.Internal;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands; namespace Volo.Abp.Cli.Commands;
@ -65,7 +68,7 @@ public class HelpCommand : IConsoleCommand, ITransientDependency
sb.AppendLine("Command List:"); sb.AppendLine("Command List:");
sb.AppendLine(""); 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); var method = command.Value.GetMethod("GetShortDescription", BindingFlags.Static | BindingFlags.Public);
if (method == null) if (method == null)
@ -92,6 +95,11 @@ public class HelpCommand : IConsoleCommand, ITransientDependency
return sb.ToString(); return sb.ToString();
} }
private bool NotHiddenFromCommandList(KeyValuePair<string, Type> command)
{
return command.Value.GetCustomAttribute(typeof(HideFromCommandList)) == null;
}
public static string GetShortDescription() public static string GetShortDescription()
{ {
return "Show command line help. Write ` abp help <command> `"; return "Show command line help. Write ` abp help <command> `";

6
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
{}
Loading…
Cancel
Save