mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Introduce ICommand
This commit is contained in:
@@ -4,7 +4,7 @@ using CliFx.Models;
|
|||||||
|
|
||||||
namespace CliFx
|
namespace CliFx
|
||||||
{
|
{
|
||||||
public abstract class Command
|
public abstract class Command : ICommand
|
||||||
{
|
{
|
||||||
public virtual ExitCode Execute() => throw new InvalidOperationException(
|
public virtual ExitCode Execute() => throw new InvalidOperationException(
|
||||||
"Can't execute command because its execution method is not defined. " +
|
"Can't execute command because its execution method is not defined. " +
|
||||||
|
|||||||
10
CliFx/ICommand.cs
Normal file
10
CliFx/ICommand.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using CliFx.Models;
|
||||||
|
|
||||||
|
namespace CliFx
|
||||||
|
{
|
||||||
|
public interface ICommand
|
||||||
|
{
|
||||||
|
Task<ExitCode> ExecuteAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,9 +33,7 @@ namespace CliFx.Internal
|
|||||||
internal partial class CommandType
|
internal partial class CommandType
|
||||||
{
|
{
|
||||||
public static bool IsValid(Type type) =>
|
public static bool IsValid(Type type) =>
|
||||||
// Derives from Command
|
type.GetInterfaces().Contains(typeof(ICommand)) &&
|
||||||
type.IsDerivedFrom(typeof(Command)) &&
|
|
||||||
// Marked with DefaultCommandAttribute or CommandAttribute
|
|
||||||
type.IsDefined(typeof(CommandAttribute));
|
type.IsDefined(typeof(CommandAttribute));
|
||||||
|
|
||||||
public static CommandType Initialize(Type type)
|
public static CommandType Initialize(Type type)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace CliFx.Services
|
|||||||
$"Apply {nameof(CommandAttribute)} to give command a name.");
|
$"Apply {nameof(CommandAttribute)} to give command a name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command ResolveCommand(CommandOptionSet optionSet)
|
public ICommand ResolveCommand(CommandOptionSet optionSet)
|
||||||
{
|
{
|
||||||
// Get command type
|
// Get command type
|
||||||
var commandType = !optionSet.CommandName.IsNullOrWhiteSpace()
|
var commandType = !optionSet.CommandName.IsNullOrWhiteSpace()
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ namespace CliFx.Services
|
|||||||
{
|
{
|
||||||
public interface ICommandResolver
|
public interface ICommandResolver
|
||||||
{
|
{
|
||||||
Command ResolveCommand(CommandOptionSet optionSet);
|
ICommand ResolveCommand(CommandOptionSet optionSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user