Skip to content

Commit

Permalink
fix, AddSubCommands<T> does not use NameConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 3, 2022
1 parent 57b8ec9 commit 0b8cdef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion sandbox/Net6Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,32 @@
using ZLogger;


ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}"));

var app = ConsoleApp.Create(args);

app.AddSubCommands<FooBarBaz>();

//app.AddAllCommandType();

app.Run();

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

public class FooBarBaz : ConsoleAppBase
{
public void EchoNano(string msg, int repeat = 3)
{
for (var i = 0; i < repeat; i++)
{
Console.WriteLine(msg);
}
}

public void Sum([Option(0)] int x, [Option(1)] int y)
{
Console.WriteLine((x + y).ToString());
}
}


//static int Hello([Option("m")]string message, [Option("e")] bool end, [Option("r")] int repeat = 3)
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleAppFramework/ConsoleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public ConsoleApp AddSubCommands<T>()
{
var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

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

foreach (var method in methods)
{
Expand Down

0 comments on commit 0b8cdef

Please sign in to comment.