-
Notifications
You must be signed in to change notification settings - Fork 876
Expand file tree
/
Copy pathArgumentsExecutionConfigurationGatherer.cs
More file actions
36 lines (31 loc) · 1.46 KB
/
ArgumentsExecutionConfigurationGatherer.cs
File metadata and controls
36 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Logging;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// Gathers command line arguments for resources.
/// </summary>
internal class ArgumentsExecutionConfigurationGatherer : IExecutionConfigurationGatherer
{
/// <inheritdoc/>
public async ValueTask GatherAsync(IExecutionConfigurationGathererContext context, IResource resource, ILogger resourceLogger, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken = default)
{
if (resource.TryGetAnnotationsOfType<CommandLineArgsCallbackAnnotation>(out var argumentAnnotations))
{
IList<object> args = [.. context.Arguments];
var callbackContext = new CommandLineArgsCallbackContext(args, resource, cancellationToken)
{
Logger = resourceLogger,
ExecutionContext = executionContext
};
foreach (var ann in argumentAnnotations)
{
// Each annotation operates on a shared context.
args = await ann.AsCallbackAnnotation().EvaluateOnceAsync(callbackContext).ConfigureAwait(false);
}
// Take the final result and apply to the gatherer context.
context.Arguments.Clear();
context.Arguments.AddRange(args);
}
}
}