Skip to content

Commit f737bb6

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 31da0bc + 6dacbdb commit f737bb6

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
using ConsoleAppFramework;
22

3-
var app = ConsoleApp.Create();
43

5-
app.Add("build|b", () => { });
6-
app.Add("keyvault|kv", () => { });
7-
app.Add<Commands>();
4+
args = ["--x", "3", "--y", "5"];
85

9-
app.Run(args);
6+
await ConsoleApp.RunAsync(args, async (int x, int y) => { });
107

11-
public class Commands
8+
static void Foo(int x, int y)
129
{
13-
/// <summary>
14-
/// Executes the check command using the specified coordinates.
15-
/// </summary>
16-
[Command("check|c")]
17-
public void Check() { }
18-
19-
/// <summary>Build this packages's and its dependencies' documenation.</summary>
20-
[Command("doc|d")]
21-
public void Doc() { }
10+
Console.WriteLine(x + y);
2211
}

src/ConsoleAppFramework/CommandHelpBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static string BuildCommandHelpMessage(Command command)
4949

5050
public static string BuildCliSchema(IEnumerable<Command> commands)
5151
{
52-
return "return new[] {\n"
52+
return "return new CommandHelpDefinition[] {\n"
5353
+ string.Join(", \n", commands.Select(x => CreateCommandHelpDefinition(x).ToCliSchema()))
5454
+ "\n};";
5555
}

src/ConsoleAppFramework/ConsoleAppBaseCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static Action<string> LogError
235235
/// ConsoleApp.Run(args, Foo);<br/>
236236
/// ConsoleApp.Run(args, &amp;Foo);<br/>
237237
/// </summary>
238-
public static void Run(string[] args)
238+
public static void Run(string[] args, Delegate command)
239239
{
240240
}
241241
@@ -245,7 +245,7 @@ public static void Run(string[] args)
245245
/// ConsoleApp.RunAsync(args, Foo);<br/>
246246
/// ConsoleApp.RunAsync(args, &amp;Foo);<br/>
247247
/// </summary>
248-
public static Task RunAsync(string[] args)
248+
public static Task RunAsync(string[] args, Delegate command)
249249
{
250250
return Task.CompletedTask;
251251
}

src/ConsoleAppFramework/ConsoleAppGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void EmitConsoleAppRun(SourceProductionContext sourceProductionContext, C
221221
var emitter = new Emitter(null);
222222
var requiredParsableParameterCount = command.Parameters.Count(p => p.IsParsable && p.RequireCheckArgumentParsed);
223223
var withId = new Emitter.CommandWithId(null, command, -1, requiredParsableParameterCount);
224-
emitter.EmitRun(sb, withId, command.IsAsync, null);
224+
emitter.EmitRun(sb, withId, commandContext.IsAsync, null);
225225
}
226226
sourceProductionContext.AddSource("ConsoleApp.Run.g.cs", sb.ToString().ReplaceLineEndings());
227227

src/ConsoleAppFramework/Emitter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ public void EmitConfigure(SourceBuilder sb, DllReference dllReference)
963963
{
964964
sb.AppendLine("return;");
965965
}
966+
sb.AppendLine("isRequireCallBuildAndSetServiceProvider = false;");
966967

967968
if (dllReference.HasConfiguration)
968969
{

tests/ConsoleAppFramework.GeneratorTests/RunTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,44 @@ public void ArgumentLastParams()
284284

285285
verifier.Execute(code, "--opt1 abc a b c d", "abc, a|b|c|d");
286286
}
287+
288+
[Fact]
289+
public void RunAndRunAsyncOverloads()
290+
{
291+
verifier.Execute("""
292+
ConsoleApp.Run(args, () => Console.Write("sync"));
293+
""", "", "sync");
294+
295+
verifier.Execute("""
296+
ConsoleApp.Run(args, async () => Console.Write("async"));
297+
""", "", "async");
298+
299+
verifier.Execute("""
300+
await ConsoleApp.RunAsync(args, () => Console.Write("sync"));
301+
""", "", "sync");
302+
303+
verifier.Execute("""
304+
await ConsoleApp.RunAsync(args, async () => Console.Write("async"));
305+
""", "", "async");
306+
}
307+
308+
[Fact]
309+
public void RunAndRunAsyncOverloadsWithCancellationToken()
310+
{
311+
verifier.Execute("""
312+
ConsoleApp.Run(args, (CancellationToken cancellationToken) => Console.Write("sync"));
313+
""", "", "sync");
314+
315+
verifier.Execute("""
316+
ConsoleApp.Run(args, async (CancellationToken cancellationToken) => Console.Write("async"));
317+
""", "", "async");
318+
319+
verifier.Execute("""
320+
await ConsoleApp.RunAsync(args, (CancellationToken cancellationToken) => Console.Write("sync"));
321+
""", "", "sync");
322+
323+
verifier.Execute("""
324+
await ConsoleApp.RunAsync(args, async (CancellationToken cancellationToken) => Console.Write("async"));
325+
""", "", "async");
326+
}
287327
}

0 commit comments

Comments
 (0)