Skip to content
Open
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
56 changes: 33 additions & 23 deletions src/Aspire.Cli/Commands/ConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,36 +239,46 @@ private async Task<int> 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)
Expand Down
44 changes: 44 additions & 0 deletions tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Aspire.Cli.Commands.RootCommand>();

// 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<Aspire.Cli.Commands.RootCommand>();

// 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()
{
Expand Down
Loading