Skip to content

Commit 7d4cce1

Browse files
committed
more readme
1 parent aa5ae76 commit 7d4cce1

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

ReadMe.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public void Hello(
7979
{
8080
```
8181

82+
Method parameter will be required parameter, optional parameter will be oprional parameter. Also support boolean flag, if parameter is bool, in default it will be optional parameter and with `-foo` set true to parameter.
83+
8284
`help` command (or no argument to pass) shows there detail. This help format is same as `dotnet` command.
8385

8486
```
@@ -306,6 +308,74 @@ public class ExampleApp : ConsoleAppBase
306308

307309
> **NOTE**: If the method throws an unhandled exception, ConsoleAppFramework always set `1` to the exit code.
308310

311+
CommandAttribute
312+
---
313+
`CommandAttribute` enables subscommand on `RunConsoleAppFramework<T>()`(for single type CLI app), changes command name on `RunConsoleAppFramework()`(for muilti type command routing), also describes the description.
314+
315+
```
316+
RunConsoleAppFramework<App>();
317+
318+
public class App : ConsoleAppBase
319+
{
320+
// as Root Command(no command argument)
321+
public void Run()
322+
{
323+
}
324+
325+
[Command("sec", "sub comman of this app")]
326+
public void Second()
327+
{
328+
}
329+
}
330+
```
331+
332+
```
333+
RunConsoleAPpFramework();
334+
335+
public class App2 : ConsoleAppBase
336+
{
337+
// routing command: `app2 exec`
338+
[Command("exec", "exec app.")]
339+
public void Exec1()
340+
{
341+
}
342+
}
343+
344+
345+
public class App3 : ConsoleAppBase
346+
{
347+
// routing command: `app3 e2`
348+
[Command("e2", "exec app 2.")]
349+
public void ExecExec()
350+
{
351+
}
352+
}
353+
```
354+
355+
OptionAttribute
356+
---
357+
OptionAttribute configure parameter, it can set shortName or order index, and help description.
358+
359+
If you want to add only description, set "" or null to shortName parameter.
360+
361+
```csharp
362+
public void Hello(
363+
[Option("n", "name of send user.")]string name,
364+
[Option("r", "repeat count.")]int repeat = 3)
365+
{
366+
}
367+
368+
[Command("escape")]
369+
public void UrlEscape([Option(0, "input of this command")]string input)
370+
{
371+
}
372+
373+
[Command("unescape")]
374+
public void UrlUnescape([Option(null, "input of this command")]string input)
375+
{
376+
}
377+
```
378+
309379
Daemon
310380
---
311381
`ConsoleAppBase.Context.CancellationToken` is lifecycle token of application. In default, ConsoleAppFramework does not abort on received terminate request, you can check `CancellationToken.IsCancellationRequested` and shutdown gracefully. If use infinite-loop, it becomes daemon program.

sandbox/MultiContainedApp/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static async Task Main(string[] args)
1313
{
1414
//args = new string[] { "Bar.Hello3", "2" };
1515
//args = new string[] { "bar", "hello3", "-help" };
16-
args = new string[] { "foo", "echo", "help"};
16+
//args = new string[] { "foo", "echo", "help"};
1717
//args = new string[] { "bar.hello2", "help" };
1818

1919
await Host.CreateDefaultBuilder()
@@ -40,6 +40,7 @@ await Host.CreateDefaultBuilder()
4040
[ConsoleAppFilter(typeof(MyFilter2), Order = 9999)]
4141
public class Foo : ConsoleAppBase
4242
{
43+
[Command("ec", "My echo")]
4344
public void Echo(string msg)
4445
{
4546
Console.WriteLine(msg);

0 commit comments

Comments
 (0)