Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix(fx): don't require param array parameters not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed Jun 18, 2023
1 parent 1d86f76 commit a8bf9fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/Flandre.Framework/Common/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@ private void InferFromMethod(MethodBase method)
}

// parameter
var paramIsParamArray = param.ParameterType.IsArray &&
param.GetCustomAttribute<ParamArrayAttribute>() is not null;
Parameters.Add(new CommandParameter(
name: param.Name!,
type: param.ParameterType,
isRequired: !param.IsOptional,
isRequired: !(paramIsParamArray || param.HasDefaultValue),
defaultValue: param.HasDefaultValue ? param.DefaultValue : null,
isParamArray: param.ParameterType.IsArray &&
param.GetCustomAttribute<ParamArrayAttribute>() is not null)
{
Description = description
});
isParamArray: paramIsParamArray) { Description = description });
}
}

Expand Down
14 changes: 5 additions & 9 deletions tests/Flandre.Framework.Tests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ public static string Test5(double arg1, int arg2, [Option] bool opt1)

// Array parameter
[Command]
public static string Test6(double arg, params string[] strArr)
public string Test6(double arg, params string[] strArr)
{
return new StringBuilder()
.Append(arg)
.Append(" | ")
.Append(string.Join(',', strArr))
.ToString();
return $"{arg} | {string.Join(',', strArr)} | {strArr.Length}";
}

[Command]
Expand Down Expand Up @@ -144,10 +140,10 @@ public void TestArrayParameter()
using var app = Utils.StartTestApp<TestPlugin>(out var client);

var content = client.SendMessageForReply("test6 1.23 aaa bbb ccc ");
Assert.Equal("1.23 | aaa,bbb,ccc", content?.GetText());
Assert.Equal("1.23 | aaa,bbb,ccc | 3", content?.GetText());

content = client.SendMessageForReply("test6 2.34");
Assert.Equal("2.34 | ", content?.GetText());
Assert.Equal("2.34 | | 0", content?.GetText());
}

[Fact]
Expand Down

0 comments on commit a8bf9fa

Please sign in to comment.