Last active
February 5, 2025 11:23
-
-
Save guitarrapc/a3f724d4c00ac402cd6109ebe69f77d9 to your computer and use it in GitHub Desktop.
ConsoleAppFramework v5 cannot handle parameter not defined in method. v4 can do it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ConsoleAppFramework v4 | |
using ConsoleAppFramework; | |
// # OK | |
// # Output: foo | |
// args = ["--msg", "foo"]; | |
// # OK | |
// # Output: foo--hello bar | |
args = ["--msg", "foo", "--hello", "bar"]; | |
var app = ConsoleApp.CreateBuilder(args).Build(); | |
app.AddRootCommand((string msg, ConsoleAppContext context) => Console.WriteLine(msg + string.Join(" ", context.Arguments.Except(["--msg", msg])))); | |
await app.RunAsync(); | |
/* | |
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net8.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="ConsoleAppFramework" Version="4.2.4" /> | |
</ItemGroup> | |
</Project> | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ConsoleAppFramework v5 | |
using ConsoleAppFramework; | |
// # OK | |
// # Output: foo | |
// args = ["--msg", "foo"]; | |
// # NG | |
// # Output: Argument '--hello' is not recognized. | |
// args = ["--msg", "foo", "--hello", "bar"]; | |
// # OK | |
// # Output: foo--hello bar | |
args = ["--msg", "foo", "--arguments", "--hello", "bar"]; | |
var app = ConsoleApp.Create(); | |
app.Add("", (string msg, params string[] arguments) => Console.WriteLine(msg + string.Join(" ", arguments))); | |
await app.RunAsync(args); | |
/* | |
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net8.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="ConsoleAppFramework" Version="5.3.4"> | |
<PrivateAssets>all</PrivateAssets> | |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
</PackageReference> | |
</ItemGroup> | |
</Project> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment