You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This simplicity is by C# 10.0 and .NET 6 new features, similar as [ASP.NET Core 6.0 Minimal APIs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis). ConsoleAppFramework is built on [.NET Generic Host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host), you can use configuration, logging, DI, lifetime management by Microsoft.Extensions packages.
9
+
This simplicity is by C# 10.0 and .NET 6 new features, similar as [ASP.NET Core 6.0 Minimal APIs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis).
10
+
11
+
Most minimal API is one-line(with top-level-statements, global-usings).
You can register public method as command. This provides a simple way to registering multiple commands.
30
+
31
+
```csharp
32
+
// AddCommands register as command.
33
+
// echo --msg --repeat(default = 3)
34
+
// sum [x] [y]
35
+
varapp=ConsoleApp.Create(args);
36
+
app.AddCommands<Foo>();
37
+
app.Run();
38
+
39
+
// // AddSubCommands register as sub(nested) command.
40
+
// // foo echo --msg --repeat(default = 3)
41
+
// // foo sum [x] [y]
42
+
// app.AddSubCommands<Foo>();
43
+
// app.Run();
44
+
45
+
publicclassFoo : ConsoleAppBase
46
+
{
47
+
publicvoidEcho(stringmsg, intrepeat=3)
48
+
{
49
+
for (vari=0; i<repeat; i++)
50
+
{
51
+
Console.WriteLine(msg);
52
+
}
53
+
}
54
+
55
+
publicvoidSum([Option(0)]intx, [Option(1)]inty)
56
+
{
57
+
Console.WriteLine((x+y).ToString());
58
+
}
59
+
}
60
+
```
61
+
62
+
If you have many commands, you can define class separetely and use `AddAllCommandType` to register all commands one-line.
63
+
64
+
```csharp
65
+
// register `Foo` and `Bar` as SubCommands.
66
+
// foo echo --msg
67
+
// foo sum [x] [y]
68
+
// bar hello2
69
+
varapp=ConsoleApp.Create(args);
70
+
app.AddAllCommandType();
71
+
app.Run();
72
+
73
+
publicclassFoo : ConsoleAppBase
74
+
{
75
+
publicvoidEcho(stringmsg)
76
+
{
77
+
Console.WriteLine(msg);
78
+
}
79
+
80
+
publicvoidSum([Option(0)]intx, [Option(1)]inty)
81
+
{
82
+
Console.WriteLine((x+y).ToString());
83
+
}
84
+
}
85
+
86
+
publicclassBar : ConsoleAppBase
87
+
{
88
+
publicvoidHello2()
89
+
{
90
+
Console.WriteLine("H E L L O");
91
+
}
92
+
}
93
+
```
94
+
95
+
ConsoleAppFramework is built on [.NET Generic Host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host), you can use configuration, logging, DI, lifetime management by Microsoft.Extensions packages. ConsoleAppFramework do parameter binding from string args, routing many commands, dotnet style help builder, etc.
Here is the full-sample of power of ConsoleAppFramework.
10
100
11
101
```csharp
12
102
// You can use full feature of Generic Host(same as ASP.NET Core).
@@ -92,10 +182,6 @@ public class MyConfig
92
182
93
183
ConsoleAppFramework can create easily to many command application. Also enable to use GenericHost configuration is best way to share configuration/workflow when creating batch application for other .NET web app. If tool is for CI, git pull and run by `dotnet run -- [Command] [Option]` is very helpful.
94
184
95
-
ConsoleAppFramework do parameter binding from string args, routing many commands, dotnet style help builder, etc.
dotnet's standard CommandLine api - [System.CommandLine](https://github.com/dotnet/command-line-api) is low level, require many boilerplate codes. ConsoleAppFramework is like ASP.NET Core in CLI Applications, no needs boilerplate. However, with the power of Generic Host, it is simple and easy, but much more powerful.
100
186
101
187
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
0 commit comments