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
ConsoleAppFramework is an analyzer (Source Generator) and does not have any dll references. When referenced, the entry point class `ConsoleAppFramework.ConsoleApp` is generated internally.
163
165
@@ -423,6 +425,33 @@ app.Run(args);
423
425
424
426
You can also combine this with `Add` or `Add<T>` to add more commands.
425
427
428
+
### Alias command
429
+
430
+
Similar to option aliases, commands also support aliases. In the `Add` method, separating `commandName` or `[Command]` with `|` defines them as aliases.
431
+
432
+
```csharp
433
+
usingConsoleAppFramework;
434
+
435
+
varapp=ConsoleApp.Create();
436
+
437
+
app.Add("build|b", () => { });
438
+
app.Add("keyvault|kv", () => { });
439
+
app.Add<Commands>();
440
+
441
+
app.Run(args);
442
+
443
+
publicclassCommands
444
+
{
445
+
/// <summary>Executes the check command using the specified coordinates.</summary>
446
+
[Command("check|c")]
447
+
publicvoidCheck() { }
448
+
449
+
/// <summary>Build this packages's and its dependencies' documenation.</summary>
450
+
[Command("doc|d")]
451
+
publicvoidDoc() { }
452
+
}
453
+
```
454
+
426
455
### Performance of Commands
427
456
428
457
In `ConsoleAppFramework`, the number and types of registered commands are statically determined at compile time. For example, let's register the following four commands:
@@ -571,7 +600,15 @@ When using `ConsoleApp.Run`, you can check the syntax of the command line in the
571
600
572
601
For the rules on converting parameter names to option names, aliases, and how to set documentation, refer to the [Option aliases](#option-aliases-and-help-version) section.
573
602
574
-
Parameters marked with the `[Argument]` attribute receive values in order without parameter names. This attribute can only be set on sequential parameters from the beginning.
603
+
Parameters marked with the `[Argument]` attribute receive values in order without parameter names. This attribute allows from first or last.
To convert from string arguments to various types, basic primitive types (`string`, `char`, `sbyte`, `byte`, `short`, `int`, `long`, `uint`, `ushort`, `ulong`, `decimal`, `float`, `double`) use `TryParse`. For types that implement `ISpanParsable<T>` (`DateTime`, `DateTimeOffset`, `Guid`, `BigInteger`, `Complex`, `Half`, `Int128`, etc.), [IParsable<TSelf>.TryParse](https://learn.microsoft.com/en-us/dotnet/api/system.iparsable-1.tryparse?view=net-8.0#system-ispanparsable-1-tryparse(system-readonlyspan((system-char))-system-iformatprovider-0@)) or [ISpanParsable<TSelf>.TryParse](https://learn.microsoft.com/en-us/dotnet/api/system.ispanparsable-1.tryparse?view=net-8.0#system-ispanparsable-1-tryparse(system-readonlyspan((system-char))-system-iformatprovider-0@)) is used.
577
614
@@ -1428,6 +1465,55 @@ The framework doesn't support colorization directly; however, utilities like [Cy
1428
1465
1429
1466
For more powerful Console UI support, you can also use it in combination with [Spectre.Console](https://spectreconsole.net/).
1430
1467
1468
+
Cli Schema
1469
+
---
1470
+
The dotnet command can output command and option information in JSON format using the `--cli-schema` option. In ConsoleAppFramework, by importing the `ConsoleAppFramework.CliSchema` package, you can call the `ConsoleAppBuilder.GetCliSchema()` method.
You can also convert it to JSON. Since `CliSchemaJsonSerializerContext` is provided, by passing it as a Serialize/Deserialize argument, you can perform Native AOT-compatible conversion.
There are multiple ways to run a CLI application in .NET:
@@ -1440,6 +1526,8 @@ There are multiple ways to run a CLI application in .NET:
1440
1526
1441
1527
Also, to run with Native AOT, please refer to the [Native AOT deployment overview](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/). In any case, ConsoleAppFramework thoroughly implements a dependency-free and reflection-free approach, so it shouldn't be an obstacle to execution.
1442
1528
1529
+
There is a method of distributing CLI tools by packaging them as [.NET tools](https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools). Also, starting from .NET 10, it is possible to execute them directly from the package manager using [dotnet tool exec(dnx)](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-tool-exec).
1530
+
1443
1531
v4 -> v5 Migration Guide
1444
1532
---
1445
1533
v4 was running on top of `Microsoft.Extensions.Hosting`, so build a Host in the same way and need to convert ConsoleAppBuilder.
0 commit comments