diff --git a/src/Aspire.Cli/Commands/ConfigCommand.cs b/src/Aspire.Cli/Commands/ConfigCommand.cs index 793b4a512f4..66b52483fa5 100644 --- a/src/Aspire.Cli/Commands/ConfigCommand.cs +++ b/src/Aspire.Cli/Commands/ConfigCommand.cs @@ -239,36 +239,46 @@ private async Task ExecuteAsync(bool showAll, CancellationToken cancellatio var localConfig = await ConfigurationService.GetLocalConfigurationAsync(cancellationToken); var globalConfig = await ConfigurationService.GetGlobalConfigurationAsync(cancellationToken); + var featurePrefix = $"{KnownFeatures.FeaturePrefix}."; + // Check if we have any configuration at all if (localConfig.Count == 0 && globalConfig.Count == 0) { InteractionService.DisplayMessage(KnownEmojis.Information, ConfigCommandStrings.NoConfigurationValuesFound); - return ExitCodeConstants.Success; + + if (!showAll) + { + // Show hint about --all flag when there's no config and user didn't pass --all + InteractionService.DisplayMarkupLine($" [dim]{ConfigCommandStrings.ListCommand_AllFeaturesHint.EscapeMarkup()}[/]"); + return ExitCodeConstants.Success; + } + + // showAll=true: fall through to show available features below } + else + { + // Compute max column widths across both tables for consistent alignment + var keyWidth = MaxWidth(ConfigCommandStrings.HeaderKey, localConfig.Keys, globalConfig.Keys); + var valueWidth = MaxWidth(ConfigCommandStrings.HeaderValue, localConfig.Values, globalConfig.Values); + + // Display Local Configuration + RenderConfigTable( + ConfigCommandStrings.LocalConfigurationHeader, + localConfig, + ConfigCommandStrings.NoLocalConfigurationFound, + keyWidth, + valueWidth); - var featurePrefix = $"{KnownFeatures.FeaturePrefix}."; + InteractionService.DisplayEmptyLine(); - // Compute max column widths across both tables for consistent alignment - var keyWidth = MaxWidth(ConfigCommandStrings.HeaderKey, localConfig.Keys, globalConfig.Keys); - var valueWidth = MaxWidth(ConfigCommandStrings.HeaderValue, localConfig.Values, globalConfig.Values); - - // Display Local Configuration - RenderConfigTable( - ConfigCommandStrings.LocalConfigurationHeader, - localConfig, - ConfigCommandStrings.NoLocalConfigurationFound, - keyWidth, - valueWidth); - - InteractionService.DisplayEmptyLine(); - - // Display Global Configuration - RenderConfigTable( - ConfigCommandStrings.GlobalConfigurationHeader, - globalConfig, - ConfigCommandStrings.NoGlobalConfigurationFound, - keyWidth, - valueWidth); + // Display Global Configuration + RenderConfigTable( + ConfigCommandStrings.GlobalConfigurationHeader, + globalConfig, + ConfigCommandStrings.NoGlobalConfigurationFound, + keyWidth, + valueWidth); + } // Display Available Features var allConfiguredFeatures = localConfig.Concat(globalConfig) diff --git a/tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs b/tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs index c528c181db8..bbc82eb3262 100644 --- a/tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs +++ b/tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs @@ -359,6 +359,50 @@ public async Task ConfigListCommand_WithAllFlag_ShowsFeatureDetails() Assert.Contains("default:", output); } + [Fact] + public async Task ConfigListCommand_WithoutAllFlag_NoConfig_ShowsHintAboutAllFlag() + { + using var workspace = TemporaryWorkspace.Create(outputHelper); + var outputWriter = new TestOutputTextWriter(outputHelper); + var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options => + { + options.OutputTextWriter = outputWriter; + }); + var provider = services.BuildServiceProvider(); + + var command = provider.GetRequiredService(); + + // List without --all and with no config set + var listResult = command.Parse("config list"); + var listExitCode = await listResult.InvokeAsync().DefaultTimeout(); + Assert.Equal(0, listExitCode); + + var output = string.Join("\n", outputWriter.Logs); + Assert.Contains("--all", output); + } + + [Fact] + public async Task ConfigListCommand_WithAllFlag_NoConfig_ShowsAvailableFeatures() + { + using var workspace = TemporaryWorkspace.Create(outputHelper); + var outputWriter = new TestOutputTextWriter(outputHelper); + var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options => + { + options.OutputTextWriter = outputWriter; + }); + var provider = services.BuildServiceProvider(); + + var command = provider.GetRequiredService(); + + // List with --all and with no config set + var listResult = command.Parse("config list --all"); + var listExitCode = await listResult.InvokeAsync().DefaultTimeout(); + Assert.Equal(0, listExitCode); + + var output = string.Join("\n", outputWriter.Logs); + Assert.Contains("default:", output); + } + [Fact] public async Task FeatureFlags_WhenSetToTrue_ReturnsTrue() {