Skip to content

Commit c784d76

Browse files
committed
cleanup readme
1 parent 03af66e commit c784d76

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

ReadMe.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,25 @@ public MyApp(IOptions<MyConfig> config, ILogger<MyApp> logger)
627627

628628
DI also inject to filter.
629629

630+
Cleanup
631+
---
632+
You can implement `IDisposable.Dispose` explicitly, that is called after command finished.
633+
634+
```csharp
635+
public class MyApp : ConsoleAppBase, IDisposable
636+
{
637+
public void Hello()
638+
{
639+
Console.WriteLine("Hello");
640+
}
641+
642+
void IDisposable.Dispose() // NOTE: can not implement `public void Dispose()`
643+
{
644+
Console.WriteLine("DISPOSED");
645+
}
646+
}
647+
```
648+
630649
ConsoleAppContext
631650
---
632651
ConsoleAppContext is injected to property on method executing.

sandbox/SingleContainedApp/Program.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace SingleContainedApp
2020
public class MyFirstBatch : ConsoleAppBase
2121
{
2222
public void Hello(
23-
[Option("n", "name of send user.")]string name,
24-
[Option("r", "repeat count.")]int repeat = 3)
23+
[Option("n", "name of send user.")] string name,
24+
[Option("r", "repeat count.")] int repeat = 3)
2525
{
2626
for (int i = 0; i < repeat; i++)
2727
{
@@ -67,13 +67,13 @@ public void ShowVersion()
6767
}
6868

6969
[Command("escape")]
70-
public void UrlEscape([Option(0)]string input)
70+
public void UrlEscape([Option(0)] string input)
7171
{
7272
Console.WriteLine(Uri.EscapeDataString(input));
7373
}
7474

7575
[Command("timer")]
76-
public async Task Timer([Option(0)]uint waitSeconds)
76+
public async Task Timer([Option(0)] uint waitSeconds)
7777
{
7878
Console.WriteLine(waitSeconds + " seconds");
7979
while (waitSeconds != 0)
@@ -94,16 +94,16 @@ public class MyConfig
9494
public class OverrideCheck : ConsoleAppBase
9595
{
9696
[Command("encode", "encode input string to base64url")]
97-
public void Encode([Option(0)]string input) => Console.WriteLine((input));
97+
public void Encode([Option(0)] string input) => Console.WriteLine((input));
9898

9999
[Command("decode", "decode input base64url to string")]
100-
public void Decode([Option(0)]string input) => Console.WriteLine((input));
100+
public void Decode([Option(0)] string input) => Console.WriteLine((input));
101101

102102
[Command("escape", "escape base64 to base64url")]
103-
public void Escape([Option(0)]string input) => Console.WriteLine((input));
103+
public void Escape([Option(0)] string input) => Console.WriteLine((input));
104104

105105
[Command(new[] { "unescape", "-h" }, "unescape base64url to base64")]
106-
public void Unescape([Option(0)]string input) => Console.WriteLine((input));
106+
public void Unescape([Option(0)] string input) => Console.WriteLine((input));
107107

108108
//[Command(new[] { "help", "-h", "-help", "--help" }, "show help")]
109109
//public void Help()
@@ -127,7 +127,7 @@ public void Foo(int[] array, Person person)
127127

128128
public class StandardArgTest : ConsoleAppBase
129129
{
130-
public void Run([Option(0, "message of x.")]string x)
130+
public void Run([Option(0, "message of x.")] string x)
131131
{
132132
// Console.WriteLine("1." + x);
133133
//Console.WriteLine("2." + y);
@@ -160,7 +160,7 @@ public async Task Throw()
160160

161161
public class SimpleTwoArgs : ConsoleAppBase
162162
{
163-
public async ValueTask<int> Hello([Option("n")]string name, [Option("r")]int repeat)
163+
public async ValueTask<int> Hello([Option("n")] string name, [Option("r")] int repeat)
164164
{
165165
Context.Logger.LogInformation($"name:{name}");
166166

@@ -217,12 +217,12 @@ void IDisposable.Dispose()
217217
// }
218218
//}
219219

220-
public class Program : ConsoleAppBase
220+
public class Program : ConsoleAppBase, IDisposable
221221
{
222222
static async Task Main(string[] args)
223223
{
224224
//args = new[] { "-m", "a ", "-b", "False" };
225-
args = new[] { "help" };
225+
args = new[] { "hello" };
226226

227227
await Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<Program>(args, new ConsoleAppOptions
228228
{
@@ -232,12 +232,18 @@ static async Task Main(string[] args)
232232

233233
}
234234

235+
235236
public void Hello(
236237
int? foo = null,
237-
[Option("", "", DefaultValue = "DateTime.Today")]DateTime? hello = null)
238+
[Option("", "", DefaultValue = "DateTime.Today")] DateTime? hello = null)
238239
{
239240
if (hello == null) hello = DateTime.Now;
240241
Console.WriteLine(hello);
241242
}
243+
public void Dispose()
244+
{
245+
Console.WriteLine("DISPOSE!");
246+
}
247+
242248
}
243249
}

0 commit comments

Comments
 (0)