Skip to content

Commit 57b8ec9

Browse files
committed
readme change
1 parent 3929156 commit 57b8ec9

File tree

1 file changed

+91
-5
lines changed

1 file changed

+91
-5
lines changed

ReadMe.md

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,97 @@ ConsoleAppFramework is an infrastructure of creating CLI(Command-line interface)
66

77
![image](https://user-images.githubusercontent.com/46207/147662718-f7756523-67a9-4295-b090-3cfc94203017.png)
88

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). 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).
12+
13+
```csharp
14+
ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}"));
15+
```
16+
17+
Of course, ConsoleAppFramework has extensibility.
18+
19+
```csharp
20+
// Regsiter two commands(use short-name, argument)
21+
// hello -m
22+
// sum [x] [y]
23+
var app = ConsoleApp.Create(args);
24+
app.AddCommand("hello", ([Option("m", "Message to display.")] string message) => Console.WriteLine($"Hello {message}"));
25+
app.AddCommand("sum", ([Option(0)] int x, [Option(1)] int y) => Console.WriteLine(x + y));
26+
app.Run();
27+
```
28+
29+
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+
var app = 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+
public class Foo : ConsoleAppBase
46+
{
47+
public void Echo(string msg, int repeat = 3)
48+
{
49+
for (var i = 0; i < repeat; i++)
50+
{
51+
Console.WriteLine(msg);
52+
}
53+
}
54+
55+
public void Sum([Option(0)]int x, [Option(1)]int y)
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+
var app = ConsoleApp.Create(args);
70+
app.AddAllCommandType();
71+
app.Run();
72+
73+
public class Foo : ConsoleAppBase
74+
{
75+
public void Echo(string msg)
76+
{
77+
Console.WriteLine(msg);
78+
}
79+
80+
public void Sum([Option(0)]int x, [Option(1)]int y)
81+
{
82+
Console.WriteLine((x + y).ToString());
83+
}
84+
}
85+
86+
public class Bar : ConsoleAppBase
87+
{
88+
public void Hello2()
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.
96+
97+
![image](https://user-images.githubusercontent.com/46207/72047323-a08e0c80-32fd-11ea-850a-7f926adf3d22.png)
98+
99+
Here is the full-sample of power of ConsoleAppFramework.
10100

11101
```csharp
12102
// You can use full feature of Generic Host(same as ASP.NET Core).
@@ -92,10 +182,6 @@ public class MyConfig
92182

93183
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.
94184

95-
ConsoleAppFramework do parameter binding from string args, routing many commands, dotnet style help builder, etc.
96-
97-
![image](https://user-images.githubusercontent.com/46207/72047323-a08e0c80-32fd-11ea-850a-7f926adf3d22.png)
98-
99185
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.
100186

101187
<!-- START doctoc generated TOC please keep comment here to allow auto update -->

0 commit comments

Comments
 (0)