Skip to content

Commit 0b8cdef

Browse files
committed
fix, AddSubCommands<T> does not use NameConverter
1 parent 57b8ec9 commit 0b8cdef

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

sandbox/Net6Console/Program.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,32 @@
88
using ZLogger;
99

1010

11-
ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}"));
11+
12+
var app = ConsoleApp.Create(args);
13+
14+
app.AddSubCommands<FooBarBaz>();
15+
16+
//app.AddAllCommandType();
17+
18+
app.Run();
1219

1320
//args = new[] { "--message", "tako" };
1421

22+
public class FooBarBaz : ConsoleAppBase
23+
{
24+
public void EchoNano(string msg, int repeat = 3)
25+
{
26+
for (var i = 0; i < repeat; i++)
27+
{
28+
Console.WriteLine(msg);
29+
}
30+
}
31+
32+
public void Sum([Option(0)] int x, [Option(1)] int y)
33+
{
34+
Console.WriteLine((x + y).ToString());
35+
}
36+
}
1537

1638

1739
//static int Hello([Option("m")]string message, [Option("e")] bool end, [Option("r")] int repeat = 3)

src/ConsoleAppFramework/ConsoleApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public ConsoleApp AddSubCommands<T>()
145145
{
146146
var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
147147

148-
var rootName = typeof(T).GetCustomAttribute<CommandAttribute>()?.CommandNames[0] ?? typeof(T).Name;
148+
var rootName = typeof(T).GetCustomAttribute<CommandAttribute>()?.CommandNames[0] ?? options.NameConverter(typeof(T).Name);
149149

150150
foreach (var method in methods)
151151
{

0 commit comments

Comments
 (0)