Skip to content

Commit 0a53f8f

Browse files
committed
Fix --version enable on ConsoleAppBuilder
1 parent a46b781 commit 0a53f8f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

sandbox/GeneratorSandbox/Program.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using ConsoleAppFramework;
22
using FilterShareProject;
3+
using System.Reflection;
4+
35
//using Microsoft.Extensions.DependencyInjection;
46
using System.Runtime.CompilerServices;
57

6-
7-
args = ["Output"];
8-
8+
args = ["--version"];
9+
Console.WriteLine(args.Length);
10+
Console.WriteLine(args.AsSpan(0).Length);
911

1012
// ConsoleApp.ServiceProvider
1113
// ConsoleApp.Create(
1214

1315

16+
// ConsoleApp.Run(args, (int x, int y) => { });
1417
var app = ConsoleApp.Create();
15-
16-
// var app = ConsoleApp.Create();
17-
18-
// app.Add<MyCommands>();
19-
app.Add<MyCommands>();
18+
app.Add<MyCommands>("zzz");
2019

2120
app.Run(args);
2221

src/ConsoleAppFramework/Emitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void EmitLeafCommand(CommandWithId? command)
500500
{
501501
if (command == null)
502502
{
503-
sb.AppendLine("ShowHelp(-1);");
503+
sb.AppendLine($"if (!TryShowHelpOrVersion(args.AsSpan({depth}), -1, -1)) ShowHelp(-1);");
504504
}
505505
else
506506
{

tests/ConsoleAppFramework.GeneratorTests/HelpTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ public void Version()
3434
expected: """
3535
9999.9999999abcdefg
3636
37+
""");
38+
}
39+
40+
[Fact]
41+
public void VersionOnBuilder()
42+
{
43+
var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "1.0.0";
44+
45+
verifier.Execute(code: """
46+
var app = ConsoleApp.Create();
47+
app.Run(args);
48+
""",
49+
args: "--version",
50+
expected: $$"""
51+
{{version}}
52+
3753
""");
3854
}
3955

0 commit comments

Comments
 (0)