Skip to content

Add 'aspire dashboard' CLI command#15607

Draft
JamesNK wants to merge 1 commit intomainfrom
cli-dashboard-command
Draft

Add 'aspire dashboard' CLI command#15607
JamesNK wants to merge 1 commit intomainfrom
cli-dashboard-command

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 26, 2026

Description

Add a new aspire dashboard CLI command that starts a standalone Aspire Dashboard instance using the aspire-managed dashboard binary from the CLI bundle.

Features:

  • Foreground mode (default): Runs the dashboard blocking until Ctrl+C, with console output visible to the user
  • Detach mode (--detach): Starts the dashboard in the background, prints the PID, and exits
  • Pass-through arguments: Any unmatched arguments are forwarded to the dashboard process (e.g., aspire dashboard -- --urls http://localhost:18888)

Implementation details:

  • Discovers the aspire-managed binary via ILayoutDiscovery and the existing bundle layout system
  • Foreground mode uses LayoutProcessRunner.Start() with no output redirection (dashboard inherits the console)
  • Detach mode uses DetachedProcessLauncher.Start() for clean background process launching
  • Errors clearly if the CLI bundle is not available
  • Categorized under the Monitoring help group alongside telemetry/otel commands

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings March 26, 2026 06:32
@github-actions
Copy link
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15607

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15607"

@JamesNK JamesNK marked this pull request as draft March 26, 2026 06:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new aspire dashboard top-level CLI command to launch the standalone Aspire Dashboard via the bundled aspire-managed binary, integrating it into the root command set and localized resources.

Changes:

  • Registers a new DashboardCommand in the CLI host and root command, categorized under the Monitoring help group.
  • Implements foreground and --detach execution paths and introduces localized resource strings for the new command.
  • Adds initial unit tests covering --help and the “bundle not available” error case.

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs Registers DashboardCommand in the test DI container.
tests/Aspire.Cli.Tests/Commands/DashboardCommandTests.cs Adds tests for help and missing-bundle error behavior.
src/Aspire.Cli/Program.cs Registers DashboardCommand in the production DI container.
src/Aspire.Cli/Commands/RootCommand.cs Adds dashboard as a root subcommand.
src/Aspire.Cli/Commands/DashboardCommand.cs Implements the new aspire dashboard command (foreground/detach + arg pass-through).
src/Aspire.Cli/Resources/DashboardCommandStrings.resx Adds new localized strings for the dashboard command.
src/Aspire.Cli/Resources/DashboardCommandStrings.Designer.cs Strongly-typed accessor for the new dashboard strings.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.cs.xlf Localization XLF for cs.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.de.xlf Localization XLF for de.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.es.xlf Localization XLF for es.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.fr.xlf Localization XLF for fr.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.it.xlf Localization XLF for it.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.ja.xlf Localization XLF for ja.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.ko.xlf Localization XLF for ko.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.pl.xlf Localization XLF for pl.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.pt-BR.xlf Localization XLF for pt-BR.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.ru.xlf Localization XLF for ru.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.tr.xlf Localization XLF for tr.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.zh-Hans.xlf Localization XLF for zh-Hans.
src/Aspire.Cli/Resources/xlf/DashboardCommandStrings.zh-Hant.xlf Localization XLF for zh-Hant.
Files not reviewed (1)
  • src/Aspire.Cli/Resources/DashboardCommandStrings.Designer.cs: Language not supported

Comment on lines +67 to +78
var dashboardArgs = new List<string> { "dashboard" };
dashboardArgs.AddRange(parseResult.UnmatchedTokens);

var detach = parseResult.GetValue(s_detachOption);

if (detach)
{
return ExecuteDetached(managedPath, dashboardArgs);
}

return await ExecuteForegroundAsync(managedPath, dashboardArgs, cancellationToken).ConfigureAwait(false);
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current tests cover --help and the bundle-not-available failure, but they don't cover the new argument pass-through behavior (especially handling of --), or the detach/foreground launch paths. Add unit tests that verify the forwarded argument list and the --detach behavior (e.g., by introducing an injectable process launcher abstraction so tests can assert the executable/args/working directory without spawning real processes).

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +69
dashboardArgs.AddRange(parseResult.UnmatchedTokens);

Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseResult.UnmatchedTokens can include the "--" delimiter (see how ExecCommand explicitly searches for it). Forwarding the delimiter to aspire-managed dashboard will cause everything after it to be treated as positional args, so aspire dashboard -- --urls ... won't work as intended. Strip the delimiter before appending pass-through args (i.e., forward only the tokens after -- when present).

Suggested change
dashboardArgs.AddRange(parseResult.UnmatchedTokens);
var unmatchedTokens = parseResult.UnmatchedTokens;
var startIndex = 0;
for (var i = 0; i < unmatchedTokens.Count; i++)
{
if (unmatchedTokens[i] == "--")
{
startIndex = i + 1;
break;
}
}
for (var i = startIndex; i < unmatchedTokens.Count; i++)
{
dashboardArgs.Add(unmatchedTokens[i]);
}

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +86
var process = DetachedProcessLauncher.Start(managedPath, dashboardArgs, Directory.GetCurrentDirectory());

_interactionService.DisplayMessage(KnownEmojis.Rocket,
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detached mode uses Directory.GetCurrentDirectory() for the child process working directory, which can diverge from ExecutionContext.WorkingDirectory (notably in tests and when the CLI changes working directory semantics). Use ExecutionContext.WorkingDirectory.FullName (and consider passing the same working directory to LayoutProcessRunner.Start for consistency).

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +118
var process = DetachedProcessLauncher.Start(managedPath, dashboardArgs, Directory.GetCurrentDirectory());

_interactionService.DisplayMessage(KnownEmojis.Rocket,
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardStarted, process.Id));

return ExitCodeConstants.Success;
}

private async Task<int> ExecuteForegroundAsync(string managedPath, List<string> dashboardArgs, CancellationToken cancellationToken)
{
_logger.LogDebug("Starting dashboard in foreground: {ManagedPath}", managedPath);

using var process = LayoutProcessRunner.Start(managedPath, dashboardArgs, redirectOutput: false);

try
{
await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
if (!process.HasExited)
{
process.Kill(entireProcessTree: true);
}

return ExitCodeConstants.Success;
}

if (process.ExitCode != 0)
{
_interactionService.DisplayError(
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardExitedWithError, process.ExitCode));
}

return process.ExitCode == 0 ? ExitCodeConstants.Success : ExitCodeConstants.DashboardFailure;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DetachedProcessLauncher.Start(...) / LayoutProcessRunner.Start(...) can throw (e.g., permission issues, missing execute bit, invalid binary). Right now those exceptions bubble to the top-level handler and become a generic "unexpected error" with exit code 1, rather than returning ExitCodeConstants.DashboardFailure with a dashboard-specific message. Catch exceptions around process start/launch and convert them into a clear DisplayError(...) + DashboardFailure exit code.

Suggested change
var process = DetachedProcessLauncher.Start(managedPath, dashboardArgs, Directory.GetCurrentDirectory());
_interactionService.DisplayMessage(KnownEmojis.Rocket,
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardStarted, process.Id));
return ExitCodeConstants.Success;
}
private async Task<int> ExecuteForegroundAsync(string managedPath, List<string> dashboardArgs, CancellationToken cancellationToken)
{
_logger.LogDebug("Starting dashboard in foreground: {ManagedPath}", managedPath);
using var process = LayoutProcessRunner.Start(managedPath, dashboardArgs, redirectOutput: false);
try
{
await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
if (!process.HasExited)
{
process.Kill(entireProcessTree: true);
}
return ExitCodeConstants.Success;
}
if (process.ExitCode != 0)
{
_interactionService.DisplayError(
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardExitedWithError, process.ExitCode));
}
return process.ExitCode == 0 ? ExitCodeConstants.Success : ExitCodeConstants.DashboardFailure;
try
{
var process = DetachedProcessLauncher.Start(managedPath, dashboardArgs, Directory.GetCurrentDirectory());
_interactionService.DisplayMessage(
KnownEmojis.Rocket,
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardStarted, process.Id));
return ExitCodeConstants.Success;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to start dashboard in detached mode: {ManagedPath}", managedPath);
_interactionService.DisplayError(
string.Format(CultureInfo.CurrentCulture, "Failed to start Aspire dashboard: {0}", ex.Message));
return ExitCodeConstants.DashboardFailure;
}
}
private async Task<int> ExecuteForegroundAsync(string managedPath, List<string> dashboardArgs, CancellationToken cancellationToken)
{
_logger.LogDebug("Starting dashboard in foreground: {ManagedPath}", managedPath);
try
{
using var process = LayoutProcessRunner.Start(managedPath, dashboardArgs, redirectOutput: false);
try
{
await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
if (!process.HasExited)
{
process.Kill(entireProcessTree: true);
}
return ExitCodeConstants.Success;
}
if (process.ExitCode != 0)
{
_interactionService.DisplayError(
string.Format(CultureInfo.CurrentCulture, DashboardCommandStrings.DashboardExitedWithError, process.ExitCode));
}
return process.ExitCode == 0 ? ExitCodeConstants.Success : ExitCodeConstants.DashboardFailure;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to start dashboard in foreground: {ManagedPath}", managedPath);
_interactionService.DisplayError(
string.Format(CultureInfo.CurrentCulture, "Failed to start Aspire dashboard: {0}", ex.Message));
return ExitCodeConstants.DashboardFailure;
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 56a4214)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23580864045

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants