Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Aspire.Cli/Commands/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ internal sealed class AddCommand : BaseCommand
private readonly DotNetCliRunner _runner;
private readonly INuGetPackageCache _nuGetPackageCache;

public AddCommand(DotNetCliRunner runner, INuGetPackageCache nuGetPackageCache) : base("add", "Add an integration or other resource to the Aspire project.")
public AddCommand(DotNetCliRunner runner, INuGetPackageCache nuGetPackageCache)
: base("add", "Add an integration to the Aspire project.")
{
ArgumentNullException.ThrowIfNull(runner, nameof(runner));
ArgumentNullException.ThrowIfNull(nuGetPackageCache, nameof(nuGetPackageCache));
_runner = runner;
_nuGetPackageCache = nuGetPackageCache;

var resourceArgument = new Argument<string>("resource");
resourceArgument.Arity = ArgumentArity.ZeroOrOne;
Arguments.Add(resourceArgument);
var integrationArgument = new Argument<string>("integration");
integrationArgument.Description = "The name of the integration to add (e.g. redis, postgres).";
integrationArgument.Arity = ArgumentArity.ZeroOrOne;
Arguments.Add(integrationArgument);

var projectOption = new Option<FileInfo?>("--project");
projectOption.Description = "The path to the project file to add the integration to.";
projectOption.Validators.Add(ProjectFileHelper.ValidateProjectOption);
Options.Add(projectOption);

var versionOption = new Option<string>("--version", "-v");
versionOption.Description = "The version of the integration to add.";
Options.Add(versionOption);

var prereleaseOption = new Option<bool>("--prerelease");
prereleaseOption.Description = "Include pre-release versions of the integration when searching.";
Options.Add(prereleaseOption);

var sourceOption = new Option<string?>("--source", "-s");
sourceOption.Description = "The NuGet source to use for the integration.";
Options.Add(sourceOption);
}

Expand All @@ -46,7 +52,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell

try
{
var integrationName = parseResult.GetValue<string>("resource");
var integrationName = parseResult.GetValue<string>("integration");

var passedAppHostProjectFile = parseResult.GetValue<FileInfo?>("--project");
var effectiveAppHostProjectFile = ProjectFileHelper.UseOrFindAppHostProjectFile(passedAppHostProjectFile);
Expand Down
8 changes: 7 additions & 1 deletion src/Aspire.Cli/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@ internal sealed class NewCommand : BaseCommand
private readonly DotNetCliRunner _runner;
private readonly INuGetPackageCache _nuGetPackageCache;

public NewCommand(DotNetCliRunner runner, INuGetPackageCache nuGetPackageCache) : base("new", "Create a new Aspire sample project.")
public NewCommand(DotNetCliRunner runner, INuGetPackageCache nuGetPackageCache)
: base("new", "Create a new Aspire sample project.")
{
ArgumentNullException.ThrowIfNull(runner, nameof(runner));
ArgumentNullException.ThrowIfNull(nuGetPackageCache, nameof(nuGetPackageCache));
_runner = runner;
_nuGetPackageCache = nuGetPackageCache;

var templateArgument = new Argument<string>("template");
templateArgument.Description = "The name of the project template to use (e.g. aspire-starter, aspire).";
templateArgument.Arity = ArgumentArity.ZeroOrOne;
Arguments.Add(templateArgument);

var nameOption = new Option<string>("--name", "-n");
nameOption.Description = "The name of the project to create.";
Options.Add(nameOption);

var outputOption = new Option<string?>("--output", "-o");
outputOption.Description = "The output path for the project.";
Options.Add(outputOption);

var sourceOption = new Option<string?>("--source", "-s");
sourceOption.Description = "The NuGet source to use for the project templates.";
Options.Add(sourceOption);

var templateVersionOption = new Option<string?>("--version", "-v");
templateVersionOption.Description = "The version of the project templates to use.";
Options.Add(templateVersionOption);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Aspire.Cli/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ internal sealed class PublishCommand : BaseCommand
private readonly ActivitySource _activitySource = new ActivitySource(nameof(PublishCommand));
private readonly DotNetCliRunner _runner;

public PublishCommand(DotNetCliRunner runner) : base("publish", "Generates deployment artifacts for an Aspire app host project.")
public PublishCommand(DotNetCliRunner runner)
: base("publish", "Generates deployment artifacts for an Aspire app host project.")
{
ArgumentNullException.ThrowIfNull(runner, nameof(runner));
_runner = runner;

var projectOption = new Option<FileInfo?>("--project");
projectOption.Description = "The path to the Aspire app host project file.";
projectOption.Validators.Add(ProjectFileHelper.ValidateProjectOption);
Options.Add(projectOption);

var publisherOption = new Option<string>("--publisher", "-p");
publisherOption.Description = "The name of the publisher to use.";
Options.Add(publisherOption);

var outputPath = new Option<string>("--output-path", "-o");
outputPath.Description = "The output path for the generated artifacts.";
outputPath.DefaultValueFactory = (result) => Path.Combine(Environment.CurrentDirectory);
Options.Add(outputPath);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Aspire.Cli/Commands/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ namespace Aspire.Cli.Commands;

internal sealed class RootCommand : BaseRootCommand
{
public RootCommand(NewCommand newCommand, RunCommand runCommand, AddCommand addCommand, PublishCommand publishCommand) : base("Aspire CLI")
public RootCommand(NewCommand newCommand, RunCommand runCommand, AddCommand addCommand, PublishCommand publishCommand)
: base("The Aspire CLI can be used to create, run, and publish Aspire-based applications.")
{
var debugOption = new Option<bool>("--debug", "-d");
debugOption.Description = "Enable debug logging to the console.";
debugOption.Recursive = true;
Options.Add(debugOption);

var waitForDebuggerOption = new Option<bool>("--wait-for-debugger", "-w");
waitForDebuggerOption.Description = "Wait for a debugger to attach before executing the command.";
waitForDebuggerOption.Recursive = true;
waitForDebuggerOption.DefaultValueFactory = (result) => false;

Expand Down
13 changes: 8 additions & 5 deletions src/Aspire.Cli/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@ internal sealed class RunCommand : BaseCommand
private readonly ActivitySource _activitySource = new ActivitySource(nameof(RunCommand));
private readonly DotNetCliRunner _runner;

public RunCommand(DotNetCliRunner runner) : base("run", "Run an Aspire app host in development mode.")
public RunCommand(DotNetCliRunner runner)
: base("run", "Run an Aspire app host in development mode.")
{
ArgumentNullException.ThrowIfNull(runner, nameof(runner));

_runner = runner;

var projectArgument = new Argument<FileInfo?>("project");
projectArgument.Validators.Add(ProjectFileHelper.ValidateProjectArgument);
Arguments.Add(projectArgument);
var projectOption = new Option<FileInfo?>("--project");
projectOption.Description = "The path to the Aspire app host project file.";
projectOption.Validators.Add(ProjectFileHelper.ValidateProjectOption);
Options.Add(projectOption);

var watchOption = new Option<bool>("--watch", "-w");
watchOption.Description = "Start project resources in watch mode.";
Options.Add(watchOption);
}

protected override async Task<int> ExecuteAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
using var activity = _activitySource.StartActivity();

var passedAppHostProjectFile = parseResult.GetValue<FileInfo?>("project");
var passedAppHostProjectFile = parseResult.GetValue<FileInfo?>("--project");
var effectiveAppHostProjectFile = ProjectFileHelper.UseOrFindAppHostProjectFile(passedAppHostProjectFile);

if (effectiveAppHostProjectFile is null)
Expand Down
Loading