Skip to content

Commit 0f3a6f1

Browse files
committed
Adding Parameter Sets
Adding Parameter Sets
1 parent cd63ab3 commit 0f3a6f1

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/ResourceManager/Sql/Commands.Sql/Replication/Cmdlet/SetAzureSqlDatabaseSecondary.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ namespace Microsoft.Azure.Commands.Sql.Replication.Cmdlet
2424
/// <summary>
2525
/// Cmdlet to fail over Azure SQL Database Replication Link to the secondary database
2626
/// </summary>
27-
[Cmdlet(VerbsCommon.Set, "AzureSqlDatabaseSecondary",
27+
[Cmdlet(VerbsCommon.Set, "AzureSqlDatabaseSecondary",
28+
DefaultParameterSetName = ByDatabaseName,
2829
ConfirmImpact = ConfirmImpact.Medium)]
2930
public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
3031
{
32+
/// <summary>
33+
/// ParameterSet to set properties for a given Azure SQL Database Secondary
34+
/// </summary>
35+
internal const string ByDatabaseName = "ByDatabaseName";
36+
37+
/// <summary>
38+
/// ParameterSet to get a Replication Link by its partner Azure SQL Server Name
39+
/// </summary>
40+
internal const string ByFailoverParams = "ByFailoverParams";
41+
3142
/// <summary>
3243
/// Gets or sets the name of the primary Azure SQL Database with the replication link to remove.
3344
/// </summary>
@@ -51,8 +62,9 @@ public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
5162
/// Gets or sets a value indicating whether this is a failover.
5263
/// </summary>
5364
/// <returns></returns>
54-
[Parameter(Mandatory = false,
65+
[Parameter(Mandatory = true,
5566
ValueFromPipelineByPropertyName = false,
67+
ParameterSetName = ByFailoverParams,
5668
HelpMessage = "Whether this operation is a failover.")]
5769
public SwitchParameter Failover { get; set; }
5870

@@ -62,6 +74,7 @@ public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
6274
/// <returns></returns>
6375
[Parameter(Mandatory = false,
6476
ValueFromPipelineByPropertyName = false,
77+
ParameterSetName = ByFailoverParams,
6578
HelpMessage = "Whether this failover operation will allow data loss.")]
6679
public SwitchParameter AllowDataLoss { get; set; }
6780

@@ -91,19 +104,20 @@ protected override IEnumerable<AzureReplicationLinkModel> ApplyUserInputToModel(
91104
/// <returns>The input entity</returns>
92105
protected override IEnumerable<AzureReplicationLinkModel> PersistChanges(IEnumerable<AzureReplicationLinkModel> entity)
93106
{
94-
if (this.MyInvocation.BoundParameters.ContainsKey("Failover"))
95-
{
96-
return new List<AzureReplicationLinkModel>() { ModelAdapter.FailoverLink(this.ResourceGroupName,
97-
this.ServerName,
98-
this.DatabaseName,
99-
this.PartnerResourceGroupName,
100-
this.MyInvocation.BoundParameters.ContainsKey("AllowDataLoss") ? true : false)
101-
};
102-
}
103-
else
107+
108+
switch (ParameterSetName)
104109
{
105-
// Warning user that no options were provided so no action can be taken.
106-
WriteWarning(Resources.SetSecondaryNoOptionProvided);
110+
case ByFailoverParams:
111+
return new List<AzureReplicationLinkModel>() { ModelAdapter.FailoverLink(this.ResourceGroupName,
112+
this.ServerName,
113+
this.DatabaseName,
114+
this.PartnerResourceGroupName,
115+
this.MyInvocation.BoundParameters.ContainsKey("AllowDataLoss") ? true : false)
116+
};
117+
default:
118+
// Warning user that no options were provided so no action can be taken.
119+
WriteWarning(Resources.SetSecondaryNoOptionProvided);
120+
break;
107121
}
108122

109123
return entity;

0 commit comments

Comments
 (0)