Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ namespace Azure.Mcp.Tools.LoadTesting.Commands;

public abstract class BaseLoadTestingCommand<
[DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TOptions>
(bool resourceGroupRequired = false, bool testResourceRequired = false)
: SubscriptionCommand<TOptions> where TOptions : BaseLoadTestingOptions, new()
{
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(resourceGroupRequired
? OptionDefinitions.Common.ResourceGroup.AsRequired()
: OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(testResourceRequired
? LoadTestingOptionDefinitions.TestResource.AsRequired()
: LoadTestingOptionDefinitions.TestResource.AsOptional());
}

protected override TOptions BindOptions(ParseResult parseResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTest;

public sealed class TestCreateCommand(ILogger<TestCreateCommand> logger)
: BaseLoadTestingCommand<TestCreateOptions>
: BaseLoadTestingCommand<TestCreateOptions>(resourceGroupRequired: false, testResourceRequired: true)
{
private const string _commandTitle = "Test Create";
private readonly ILogger<TestCreateCommand> _logger = logger;
Expand Down Expand Up @@ -44,15 +44,13 @@ It will only create a test in an already existing load test resource.
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource.AsRequired());
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Test);
command.Options.Add(LoadTestingOptionDefinitions.Description);
command.Options.Add(LoadTestingOptionDefinitions.DisplayName);
command.Options.Add(LoadTestingOptionDefinitions.Endpoint);
command.Options.Add(LoadTestingOptionDefinitions.VirtualUsers);
command.Options.Add(LoadTestingOptionDefinitions.Duration);
command.Options.Add(LoadTestingOptionDefinitions.RampUpTime);
command.Options.Add(LoadTestingOptionDefinitions.Test.AsRequired());
command.Options.Add(LoadTestingOptionDefinitions.Description.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.DisplayName.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Endpoint.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.VirtualUsers.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Duration.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.RampUpTime.AsOptional());
}

protected override TestCreateOptions BindOptions(ParseResult parseResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTest;

public sealed class TestGetCommand(ILogger<TestGetCommand> logger)
: BaseLoadTestingCommand<TestGetOptions>
: BaseLoadTestingCommand<TestGetOptions>(resourceGroupRequired: false, testResourceRequired: true)
{
private const string _commandTitle = "Test Get";
private readonly ILogger<TestGetCommand> _logger = logger;
Expand All @@ -41,9 +41,7 @@ public sealed class TestGetCommand(ILogger<TestGetCommand> logger)
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource.AsRequired());
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Test);
command.Options.Add(LoadTestingOptionDefinitions.Test.AsRequired());
}

protected override TestGetOptions BindOptions(ParseResult parseResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTestResource;

public sealed class TestResourceCreateCommand(ILogger<TestResourceCreateCommand> logger)
: BaseLoadTestingCommand<TestResourceCreateOptions>
: BaseLoadTestingCommand<TestResourceCreateOptions>(resourceGroupRequired: true, testResourceRequired: false)
{
private const string _commandTitle = "Test Resource Create";
private readonly ILogger<TestResourceCreateCommand> _logger = logger;
Expand All @@ -40,8 +40,6 @@ Returns the created Load Testing resource. This creates the resource in Azure on
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
}

public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTestResource;

public sealed class TestResourceListCommand(ILogger<TestResourceListCommand> logger)
: BaseLoadTestingCommand<TestResourceListOptions>
: BaseLoadTestingCommand<TestResourceListOptions>(resourceGroupRequired: false, testResourceRequired: false)
{
private const string _commandTitle = "Test Resource List";
private readonly ILogger<TestResourceListCommand> _logger = logger;
Expand All @@ -40,8 +40,6 @@ Lists all Azure Load Testing resources available in the selected subscription an
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
}

public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTestRun;

public sealed class TestRunCreateOrUpdateCommand(ILogger<TestRunCreateOrUpdateCommand> logger)
: BaseLoadTestingCommand<TestRunCreateOrUpdateOptions>
: BaseLoadTestingCommand<TestRunCreateOrUpdateOptions>(resourceGroupRequired: false, testResourceRequired: true)
{
private const string _commandTitle = "Test Run Create or Update";
private readonly ILogger<TestRunCreateOrUpdateCommand> _logger = logger;
Expand Down Expand Up @@ -44,10 +44,8 @@ Create or update a load test run execution.
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource.AsRequired());
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.TestRun.AsRequired());
command.Options.Add(LoadTestingOptionDefinitions.Test);
command.Options.Add(LoadTestingOptionDefinitions.Test.AsRequired());
command.Options.Add(LoadTestingOptionDefinitions.DisplayName.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Description.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.OldTestRunId.AsOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Azure.Mcp.Tools.LoadTesting.Commands.LoadTestRun;

public sealed class TestRunGetCommand(ILogger<TestRunGetCommand> logger)
: BaseLoadTestingCommand<TestRunGetOptions>
: BaseLoadTestingCommand<TestRunGetOptions>(resourceGroupRequired: false, testResourceRequired: true)
{
private const string _commandTitle = "Test Run Get";
private readonly ILogger<TestRunGetCommand> _logger = logger;
Expand All @@ -43,8 +43,6 @@ public sealed class TestRunGetCommand(ILogger<TestRunGetCommand> logger)
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(LoadTestingOptionDefinitions.TestResource.AsRequired());
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.TestRun.AsOptional());
command.Options.Add(LoadTestingOptionDefinitions.Test.AsOptional());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System.Diagnostics.CodeAnalysis;
using Azure.Mcp.Core.Commands;
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Core.Extensions;
using Azure.Mcp.Core.Models.Option;
using Azure.Mcp.Tools.StorageSync.Options;
using Microsoft.Mcp.Core.Models.Option;

namespace Azure.Mcp.Tools.StorageSync.Commands;

Expand All @@ -14,11 +17,17 @@ namespace Azure.Mcp.Tools.StorageSync.Commands;
/// </summary>
public abstract class BaseStorageSyncCommand<
[DynamicallyAccessedMembers(TrimAnnotations.CommandAnnotations)] TOptions>
(bool resourceGroupRequired = true, bool storageSyncServiceRequired = true)
: SubscriptionCommand<TOptions> where TOptions : BaseStorageSyncOptions, new()
{
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
// Additional option registration can be added here for common Storage Sync options
command.Options.Add(resourceGroupRequired
? OptionDefinitions.Common.ResourceGroup.AsRequired()
: OptionDefinitions.Common.ResourceGroup.AsOptional());
command.Options.Add(storageSyncServiceRequired
? StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired()
: StorageSyncOptionDefinitions.StorageSyncService.Name.AsOptional());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.CloudEndpoint;

public sealed class CloudEndpointCreateCommand(ILogger<CloudEndpointCreateCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<CloudEndpointCreateOptions>
public sealed class CloudEndpointCreateCommand(ILogger<CloudEndpointCreateCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<CloudEndpointCreateOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Create Cloud Endpoint";
private readonly IStorageSyncService _service = service;
Expand All @@ -42,8 +43,6 @@ public sealed class CloudEndpointCreateCommand(ILogger<CloudEndpointCreateComman
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.SyncGroup.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.StorageAccountResourceId.AsRequired());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.CloudEndpoint;

public sealed class CloudEndpointDeleteCommand(ILogger<CloudEndpointDeleteCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<CloudEndpointDeleteOptions>
public sealed class CloudEndpointDeleteCommand(ILogger<CloudEndpointDeleteCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<CloudEndpointDeleteOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Delete Cloud Endpoint";
private readonly IStorageSyncService _service = service;
Expand All @@ -41,8 +42,6 @@ public sealed class CloudEndpointDeleteCommand(ILogger<CloudEndpointDeleteComman
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.SyncGroup.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.Name.AsRequired());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.CloudEndpoint;

public sealed class CloudEndpointGetCommand(ILogger<CloudEndpointGetCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<CloudEndpointGetOptions>
public sealed class CloudEndpointGetCommand(ILogger<CloudEndpointGetCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<CloudEndpointGetOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Get Cloud Endpoint";
private readonly IStorageSyncService _service = service;
Expand All @@ -43,8 +44,6 @@ public sealed class CloudEndpointGetCommand(ILogger<CloudEndpointGetCommand> log
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.SyncGroup.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.Name.AsOptional());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.CloudEndpoint;

public sealed class CloudEndpointTriggerChangeDetectionCommand(ILogger<CloudEndpointTriggerChangeDetectionCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<CloudEndpointTriggerChangeDetectionOptions>
public sealed class CloudEndpointTriggerChangeDetectionCommand(ILogger<CloudEndpointTriggerChangeDetectionCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<CloudEndpointTriggerChangeDetectionOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Trigger Change Detection";
private readonly IStorageSyncService _service = service;
Expand All @@ -41,8 +42,6 @@ public sealed class CloudEndpointTriggerChangeDetectionCommand(ILogger<CloudEndp
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.SyncGroup.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.CloudEndpoint.DirectoryPath.AsRequired());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.RegisteredServer;

public sealed class RegisteredServerGetCommand(ILogger<RegisteredServerGetCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<RegisteredServerGetOptions>
public sealed class RegisteredServerGetCommand(ILogger<RegisteredServerGetCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<RegisteredServerGetOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Get Registered Server";
private readonly IStorageSyncService _service = service;
Expand All @@ -43,8 +44,6 @@ public sealed class RegisteredServerGetCommand(ILogger<RegisteredServerGetComman
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.RegisteredServer.ServerId.AsOptional());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.RegisteredServer;

public sealed class RegisteredServerUnregisterCommand(ILogger<RegisteredServerUnregisterCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<RegisteredServerUnregisterOptions>
public sealed class RegisteredServerUnregisterCommand(ILogger<RegisteredServerUnregisterCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<RegisteredServerUnregisterOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Unregister Server";
private readonly IStorageSyncService _service = service;
Expand All @@ -41,8 +42,6 @@ public sealed class RegisteredServerUnregisterCommand(ILogger<RegisteredServerUn
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.RegisteredServer.ServerId.AsRequired());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.RegisteredServer;

public sealed class RegisteredServerUpdateCommand(ILogger<RegisteredServerUpdateCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<RegisteredServerUpdateOptions>
public sealed class RegisteredServerUpdateCommand(ILogger<RegisteredServerUpdateCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<RegisteredServerUpdateOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Update Registered Server";
private readonly IStorageSyncService _service = service;
Expand All @@ -42,8 +43,6 @@ public sealed class RegisteredServerUpdateCommand(ILogger<RegisteredServerUpdate
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.RegisteredServer.ServerId.AsRequired());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace Azure.Mcp.Tools.StorageSync.Commands.ServerEndpoint;

public sealed class ServerEndpointCreateCommand(ILogger<ServerEndpointCreateCommand> logger, IStorageSyncService service) : BaseStorageSyncCommand<ServerEndpointCreateOptions>
public sealed class ServerEndpointCreateCommand(ILogger<ServerEndpointCreateCommand> logger, IStorageSyncService service) :
BaseStorageSyncCommand<ServerEndpointCreateOptions>(resourceGroupRequired: true, storageSyncServiceRequired: true)
{
private const string CommandTitle = "Create Server Endpoint";
private readonly IStorageSyncService _service = service;
Expand All @@ -42,8 +43,6 @@ public sealed class ServerEndpointCreateCommand(ILogger<ServerEndpointCreateComm
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.StorageSyncService.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.SyncGroup.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.ServerEndpoint.Name.AsRequired());
command.Options.Add(StorageSyncOptionDefinitions.ServerEndpoint.ServerResourceId.AsRequired());
Expand Down
Loading
Loading