Skip to content
Closed
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: 1 addition & 15 deletions src/Aspire.Cli/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public UpdateCommand(
Options.Add(projectOption);

// Only add --self option if not running as dotnet tool
if (!IsRunningAsDotNetTool())
if (!CliHostEnvironment.IsRunningAsDotNetTool())
{
var selfOption = new Option<bool>("--self");
selfOption.Description = "Update the Aspire CLI itself to the latest version";
Expand All @@ -67,20 +67,6 @@ public UpdateCommand(

protected override bool UpdateNotificationsEnabled => false;

private static bool IsRunningAsDotNetTool()
{
// When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe"
// When running as a native binary, it points to "aspire" or "aspire.exe"
var processPath = Environment.ProcessPath;
if (string.IsNullOrEmpty(processPath))
{
return false;
}

var fileName = Path.GetFileNameWithoutExtension(processPath);
return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase);
}

protected override async Task<int> ExecuteAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
var isSelfUpdate = parseResult.GetValue<bool>("--self");
Expand Down
8 changes: 7 additions & 1 deletion src/Aspire.Cli/Interaction/ConsoleInteractionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ public void DisplayEmptyLine()
public void DisplayVersionUpdateNotification(string newerVersion)
{
_ansiConsole.WriteLine();
_ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NewCliVersionAvailable, newerVersion));

// Determine the update command based on how the CLI is running
var updateCommand = CliHostEnvironment.IsRunningAsDotNetTool()
? "dotnet tool update aspire.cli"
: "aspire update --self";

_ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NewCliVersionAvailable, newerVersion, updateCommand));
_ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.MoreInfoNewCliVersion, UpdateUrl));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Aspire.Cli/Resources/InteractionServiceStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@
<value>Waiting for debugger to attach to app host process</value>
</data>
<data name="NewCliVersionAvailable" xml:space="preserve">
<value>[yellow]A new version of the Aspire CLI is available: {0}[/]</value>
<comment>Do not translate [yellow] and also leave [/] as-is. {0} is the version number</comment>
<value>[yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/]</value>
<comment>Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command</comment>
</data>
<data name="MoreInfoNewCliVersion" xml:space="preserve">
<value>[dim]For more information, see: [link]{0}[/][/]</value>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Cli/Utils/CliHostEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,24 @@ private static bool IsCI(IConfiguration configuration)

return false;
}

/// <summary>
/// Determines whether the CLI is running as a dotnet tool.
/// </summary>
/// <returns>
/// <c>true</c> if the CLI is running as a dotnet tool; otherwise, <c>false</c> if running as a native binary.
/// </returns>
public static bool IsRunningAsDotNetTool()
{
// When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe"
// When running as a native binary, it points to "aspire" or "aspire.exe"
var processPath = Environment.ProcessPath;
if (string.IsNullOrEmpty(processPath))
{
return false;
}

var fileName = Path.GetFileNameWithoutExtension(processPath);
return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,33 @@ public async Task ConfirmAsync_WhenInteractiveInputNotSupported_ThrowsInvalidOpe
interactionService.ConfirmAsync("Confirm?", true, CancellationToken.None));
Assert.Contains(InteractionServiceStrings.InteractiveInputNotSupported, exception.Message);
}

[Fact]
public void DisplayVersionUpdateNotification_IncludesUpdateCommand()
{
// Arrange
var output = new StringBuilder();
var console = AnsiConsole.Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.No,
ColorSystem = ColorSystemSupport.NoColors,
Out = new AnsiConsoleOutput(new StringWriter(output))
});

var executionContext = new CliExecutionContext(new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes")));
var interactionService = new ConsoleInteractionService(console, executionContext, TestHelpers.CreateInteractiveHostEnvironment());
var version = "13.0.0-preview.1.25526.1";

// Act
interactionService.DisplayVersionUpdateNotification(version);

// Assert
var outputString = output.ToString();
Assert.Contains(version, outputString);
// The message should include an update command (either "aspire update --self" or "dotnet tool update aspire.cli")
Assert.True(
outputString.Contains("aspire update --self") || outputString.Contains("dotnet tool update aspire.cli"),
"Output should contain an update command");
Assert.Contains("https://aka.ms/aspire/update", outputString);
}
}