Skip to content

Commit 5262b87

Browse files
mitchdennyCopilot
andauthored
Add feature flag control for ExecCommand with default disabled (#10664) (#10669)
Co-authored-by: Copilot <[email protected]>
1 parent 0d40912 commit 5262b87

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/Aspire.Cli/Commands/RootCommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public RootCommand(
9494
{
9595
Subcommands.Add(deployCommand);
9696
}
97-
98-
Subcommands.Add(execCommand);
97+
98+
if (featureFlags.IsFeatureEnabled(KnownFeatures.ExecCommandEnabled, false))
99+
{
100+
Subcommands.Add(execCommand);
101+
}
99102
}
100103
}

src/Aspire.Cli/KnownFeatures.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ internal static class KnownFeatures
1010
public static string UpdateNotificationsEnabled => "updateNotificationsEnabled";
1111
public static string MinimumSdkCheckEnabled => "minimumSdkCheckEnabled";
1212
public static string DeployCommandEnabled => "deployCommandEnabled";
13+
public static string ExecCommandEnabled => "execCommandEnabled";
1314
}

tests/Aspire.Cli.Tests/Commands/ExecCommandTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public async Task ExecCommand_WhenNoProjectFileFound_ReturnsFailedToFindProject(
4242
using var workspace = TemporaryWorkspace.Create(_outputHelper);
4343
var services = CliTestHelper.CreateServiceCollection(workspace, _outputHelper, options =>
4444
{
45+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
4546
options.ProjectLocatorFactory = _ => new NoProjectFileProjectLocator();
4647
});
4748
var provider = services.BuildServiceProvider();
@@ -59,6 +60,7 @@ public async Task ExecCommand_WhenMultipleProjectFilesFound_ReturnsFailedToFindP
5960
using var workspace = TemporaryWorkspace.Create(_outputHelper);
6061
var services = CliTestHelper.CreateServiceCollection(workspace, _outputHelper, options =>
6162
{
63+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
6264
options.ProjectLocatorFactory = _ => new MultipleProjectFilesProjectLocator();
6365
});
6466
var provider = services.BuildServiceProvider();
@@ -76,6 +78,7 @@ public async Task ExecCommand_WhenProjectFileDoesNotExist_ReturnsFailedToFindPro
7678
using var workspace = TemporaryWorkspace.Create(_outputHelper);
7779
var services = CliTestHelper.CreateServiceCollection(workspace, _outputHelper, options =>
7880
{
81+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
7982
options.ProjectLocatorFactory = _ => new ProjectFileDoesNotExistLocator();
8083
});
8184
var provider = services.BuildServiceProvider();
@@ -87,6 +90,29 @@ public async Task ExecCommand_WhenProjectFileDoesNotExist_ReturnsFailedToFindPro
8790
Assert.Equal(ExitCodeConstants.FailedToFindProject, exitCode);
8891
}
8992

93+
[Fact]
94+
public async Task ExecCommand_WhenFeatureFlagEnabled_CommandAvailable()
95+
{
96+
using var workspace = TemporaryWorkspace.Create(_outputHelper);
97+
var services = CliTestHelper.CreateServiceCollection(workspace, _outputHelper, options =>
98+
{
99+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
100+
});
101+
var provider = services.BuildServiceProvider();
102+
103+
var command = provider.GetRequiredService<RootCommand>();
104+
var commandLineConfiguration = new CommandLineConfiguration(command);
105+
var testOutputWriter = new TestOutputTextWriter(_outputHelper);
106+
commandLineConfiguration.Output = testOutputWriter;
107+
108+
var result = command.Parse("exec --help", commandLineConfiguration);
109+
110+
var exitCode = await result.InvokeAsync().WaitAsync(CliTestConstants.DefaultTimeout);
111+
112+
// Should succeed because exec command is registered when feature flag is enabled
113+
Assert.Equal(ExitCodeConstants.Success, exitCode);
114+
}
115+
90116
[Fact]
91117
public async Task ExecCommand_WhenTargetResourceNotSpecified_ReturnsInvalidCommand()
92118
{
@@ -117,6 +143,7 @@ public async Task ExecCommand_ExecutesSuccessfully()
117143
using var workspace = TemporaryWorkspace.Create(_outputHelper);
118144
var services = CliTestHelper.CreateServiceCollection(workspace, _outputHelper, options =>
119145
{
146+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
120147
options.ProjectLocatorFactory = _ => new TestProjectLocator();
121148

122149
options.DotNetCliRunnerFactory = _ => new TestDotNetCliRunner

tests/Aspire.Cli.Tests/Commands/SdkInstallerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public async Task ExecCommand_WhenSdkNotInstalled_ReturnsCorrectExitCode()
118118
using var workspace = TemporaryWorkspace.Create(outputHelper);
119119
var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper, options =>
120120
{
121+
options.EnabledFeatures = [KnownFeatures.ExecCommandEnabled];
121122
options.DotNetSdkInstallerFactory = _ => new TestDotNetSdkInstaller
122123
{
123124
CheckAsyncCallback = _ => false // SDK not installed

0 commit comments

Comments
 (0)