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
Added .editorconfig file and normalized tabs to spaces
Visual Studio messes with tabs and spaces due to default setting "adaptive formatting". Adding .editorconfig file forces the indent rules and then running "dotnet format whitespace" command fixed all files in the solution.
Copy file name to clipboardExpand all lines: docs/README.md
+97-95Lines changed: 97 additions & 95 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,10 @@
2
2
3
3
# DotMake Command-Line
4
4
5
-
Declarative syntax for [System.CommandLine](https://github.com/dotnet/command-line-api) via attributes for easy, fast, strongly-typed (no reflection) usage. Includes a source generator which automagically converts your classes to CLI commands and properties to CLI options or CLI arguments. Supports [trimming](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) an [AOT compilation](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net7%2Cwindows#limitations-of-native-aot-deployment) !
6
-
7
5
System.CommandLine is a very good parser but you need a lot of boilerplate code to get going and the API is hard to discover. This becomes complicated to newcomers and also you would have a lot of ugly code in your `Program.cs` to maintain. What if you had an easy class-based layer combined with a good parser?
8
6
7
+
DotMake.CommandLine is a library which provides declarative syntax for [System.CommandLine](https://github.com/dotnet/command-line-api) via attributes for easy, fast, strongly-typed (no reflection) usage. The library includes includes a source generator which automagically converts your classes to CLI commands and properties to CLI options or CLI arguments. Supports [trimming](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) and [AOT compilation](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net7%2Cwindows#limitations-of-native-aot-deployment) !
Console.WriteLine($@"Handler for '{GetType().FullName}' is run:");
50
-
Console.WriteLine($@"Value for {nameof(Option1)} property is '{Option1}'");
51
-
Console.WriteLine($@"Value for {nameof(Argument1)} property is '{Argument1}'");
52
-
Console.WriteLine();
53
-
}
47
+
publicvoidRun()
48
+
{
49
+
Console.WriteLine($@"Handler for '{GetType().FullName}' is run:");
50
+
Console.WriteLine($@"Value for {nameof(Option1)} property is '{Option1}'");
51
+
Console.WriteLine($@"Value for {nameof(Argument1)} property is '{Argument1}'");
52
+
Console.WriteLine();
53
+
}
54
54
}
55
55
```
56
56
In Program.cs, add this single line:
@@ -67,17 +67,17 @@ To handle exceptions, you just use a try-catch block:
67
67
```c#
68
68
try
69
69
{
70
-
Cli.Run<RootCliCommand>(args);
70
+
Cli.Run<RootCliCommand>(args);
71
71
}
72
72
catch (Exceptione)
73
73
{
74
-
Console.WriteLine(@"Exception in main: {0}", e.Message);
74
+
Console.WriteLine(@"Exception in main: {0}", e.Message);
75
75
}
76
76
```
77
77
System.CommandLine, by default overtakes your exceptions that are thrown in command handlers (even if you don't set an exception handler explicitly) but DotMake.CommandLine, by default allows the exceptions to pass through. However if you wish, you can easily use an exception handler by using `configureBuilder` delegate parameter like this:
78
78
```c#
79
79
Cli.Run<RootCliCommand>(args, builder=>
80
-
builder.UseExceptionHandler((e, context) =>Console.WriteLine(@"Exception in command handler: {0}", e.Message))
80
+
builder.UseExceptionHandler((e, context) =>Console.WriteLine(@"Exception in command handler: {0}", e.Message))
-Call `Cli.Run<>` or`Cli.RunAsync<>` methodwithyourclassnametorunyourCLIapp (see [Cli](https://dotmake.build/api/html/T_DotMake_CommandLine_Cli.htm) docs for more info).
0 commit comments