Skip to content

Commit

Permalink
Support providing ReferenceExpression arguments with WithArgs()
Browse files Browse the repository at this point in the history
  • Loading branch information
afscrome committed Sep 9, 2024
1 parent 15a23b5 commit 7abf83b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Aspire.Hosting/ExecutableResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public static class ExecutableResourceBuilderExtensions
/// <param name="args">The arguments to the executable.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<ExecutableResource> AddExecutable(this IDistributedApplicationBuilder builder, string name, string command, string workingDirectory, params string[]? args)
{
return AddExecutable(builder, name, command, workingDirectory, (object[]?)args);
}

/// <summary>
/// Adds an executable resource to the application model.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="command">The executable path. This can be a fully qualified path or a executable to run from the shell/command line.</param>
/// <param name="workingDirectory">The working directory of the executable.</param>
/// <param name="args">The arguments to the executable.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<ExecutableResource> AddExecutable(this IDistributedApplicationBuilder builder, string name, string command, string workingDirectory, params object[]? args)
{
workingDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, workingDirectory));

Expand All @@ -33,7 +47,7 @@ public static IResourceBuilder<ExecutableResource> AddExecutable(this IDistribut
{
context.Args.AddRange(args);
}
});
});
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ static Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject(this Aspire.Ho
static Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject<TProject>(this Aspire.Hosting.IDistributedApplicationBuilder! builder, string! name, System.Action<Aspire.Hosting.ProjectResourceOptions!>! configure) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource!>!
static readonly Aspire.Hosting.ApplicationModel.KnownResourceStates.TerminalStates -> System.Collections.Generic.IReadOnlyList<string!>!
static readonly Aspire.Hosting.ApplicationModel.KnownResourceStates.Waiting -> string!
static Aspire.Hosting.ExecutableResourceBuilderExtensions.AddExecutable(this Aspire.Hosting.IDistributedApplicationBuilder! builder, string! name, string! command, string! workingDirectory, params object![]? args) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ExecutableResource!>!
static Aspire.Hosting.ResourceBuilderExtensions.WithArgs<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T>! builder, params object![]! args) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<T>!
12 changes: 12 additions & 0 deletions src/Aspire.Hosting/ResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public static IResourceBuilder<T> WithArgs<T>(this IResourceBuilder<T> builder,
return builder.WithArgs(context => context.Args.AddRange(args));
}

/// <summary>
/// Adds the arguments to be passed to a container resource when the container is started.
/// </summary>
/// <typeparam name="T">The resource type.</typeparam>
/// <param name="builder">The resource builder.</param>
/// <param name="args">The arguments to be passed to the container when it is started.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<T> WithArgs<T>(this IResourceBuilder<T> builder, params object[] args) where T : IResourceWithArgs
{
return builder.WithArgs(context => context.Args.AddRange(args));
}

/// <summary>
/// Adds a callback to be executed with a list of command-line arguments when a container resource is started.
/// </summary>
Expand Down

0 comments on commit 7abf83b

Please sign in to comment.