forked from PGR/ascnet
insensitive option for command argument
This commit is contained in:
parent
e69b8541af
commit
ec39e87d06
|
@ -58,14 +58,19 @@ namespace AscNet.GameServer.Commands
|
|||
public class ArgumentAttribute : Attribute
|
||||
{
|
||||
public int Position { get; }
|
||||
public Regex Pattern { get; }
|
||||
public Regex Pattern { get; set; }
|
||||
public string? Description { get; }
|
||||
public ArgumentFlags Flags { get; }
|
||||
|
||||
public ArgumentAttribute(int position, string pattern, string? description = null, ArgumentFlags flags = ArgumentFlags.None)
|
||||
{
|
||||
Position = position;
|
||||
|
||||
if ((flags & ArgumentFlags.IgnoreCase) != ArgumentFlags.IgnoreCase)
|
||||
Pattern = new(pattern);
|
||||
else
|
||||
Pattern = new(pattern, RegexOptions.IgnoreCase);
|
||||
|
||||
Description = description;
|
||||
Flags = flags;
|
||||
}
|
||||
|
@ -74,7 +79,8 @@ namespace AscNet.GameServer.Commands
|
|||
public enum ArgumentFlags
|
||||
{
|
||||
None = 0,
|
||||
Optional = 1
|
||||
Optional = 1,
|
||||
IgnoreCase = 2
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace AscNet.GameServer.Commands
|
|||
|
||||
public override string Help => "Command to interact with user's items";
|
||||
|
||||
[Argument(0, @"^add$|^clear$|^reset$", "The operation selected (add, clear, reset)")]
|
||||
[Argument(0, @"^add$|^clear$|^reset$", "The operation selected (add, clear, reset)", ArgumentFlags.IgnoreCase)]
|
||||
string Op { get; set; } = string.Empty;
|
||||
|
||||
[Argument(1, @"^[0-9]+$|^all$", "The target item, value is item id or 'all'", ArgumentFlags.Optional)]
|
||||
|
@ -22,7 +22,7 @@ namespace AscNet.GameServer.Commands
|
|||
|
||||
public override void Execute()
|
||||
{
|
||||
switch (Op)
|
||||
switch (Op.ToLower())
|
||||
{
|
||||
case "add":
|
||||
if (Target == "all")
|
||||
|
|
Loading…
Reference in New Issue