Skip to content

Commit 2da71b0

Browse files
fanglfangl
authored andcommitted
Fix remove cmdlets
1 parent 2c87d78 commit 2da71b0

File tree

10 files changed

+195
-57
lines changed

10 files changed

+195
-57
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DataSyncTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function Test-RemoveSyncAgent
9494
{
9595
# Remove the sync agent
9696
Remove-AzureRmSqlSyncAgent -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName `
97-
-SyncAgentName $saName -Confirm:$false
97+
-SyncAgentName $saName -Force
9898

9999
$all = Get-AzureRmSqlSyncAgent -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName
100100
Assert-AreEqual $all.Count 0
@@ -336,7 +336,7 @@ function Test-RemoveSyncGroup
336336
{
337337
# Remove sync group
338338
Remove-AzureRmSqlSyncGroup -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
339-
-DatabaseName $databaseName -SyncGroupName $sgName -Confirm:$false
339+
-DatabaseName $databaseName -SyncGroupName $sgName -Force
340340

341341
$all = Get-AzureRmSqlSyncGroup -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
342342
-DatabaseName $databaseName
@@ -591,7 +591,7 @@ function Test-RemoveSyncMember
591591
{
592592
# Delete a sync member
593593
Remove-AzureRmSqlSyncMember -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
594-
-DatabaseName $databaseName1 -SyncGroupName $sgName -SyncMemberName $smName -Confirm:$false
594+
-DatabaseName $databaseName1 -SyncGroupName $sgName -SyncMemberName $smName -Force
595595

596596
$all = Get-AzureRmSqlSyncMember -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
597597
-DatabaseName $databaseName1 -SyncGroupName $sgName

src/ResourceManager/Sql/Commands.Sql/Data Sync/Cmdlet/RemoveAzureSqlSyncAgent.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class RemoveAzureSqlSyncAgent : AzureSqlSyncAgentCmdletBase
3636
[ValidateNotNullOrEmpty]
3737
public string Name { get; set; }
3838

39+
/// <summary>
40+
/// Defines whether it is ok to skip the requesting of rule removal confirmation
41+
/// </summary>
42+
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
43+
public SwitchParameter Force { get; set; }
44+
3945
/// <summary>
4046
/// Defines whether the cmdlets will output the model object at the end of its execution
4147
/// </summary>
@@ -71,22 +77,18 @@ protected override IEnumerable<AzureSqlSyncAgentModel> PersistChanges(IEnumerabl
7177
}
7278

7379
/// <summary>
74-
/// Get the confirmation message when users want to remove a sync agent
75-
/// </summary>
76-
/// <returns>The confirmation message</returns>
77-
protected override string GetConfirmActionProcessMessage()
78-
{
79-
return string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncAgentDescription, this.Name);
80-
}
81-
82-
/// <summary>
83-
/// Get resource id for confirmation message
80+
/// Entry point for the cmdlet
8481
/// </summary>
85-
/// <param name="model">The sync agent that this cmdlet operates on</param>
86-
/// <returns>The resource id</returns>
87-
protected override string GetResourceId(IEnumerable<AzureSqlSyncAgentModel> model)
82+
public override void ExecuteCmdlet()
8883
{
89-
return this.ServerName;
84+
if (!Force.IsPresent && !ShouldProcess(
85+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncAgentDescription, this.Name),
86+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncAgentWarning, this.Name, this.ResourceGroupName),
87+
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption))
88+
{
89+
return;
90+
}
91+
base.ExecuteCmdlet();
9092
}
9193
}
9294
}

src/ResourceManager/Sql/Commands.Sql/Data Sync/Cmdlet/RemoveAzureSqlSyncGroup.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class RemoveAzureSqlSyncGroup : AzureSqlSyncGroupCmdletBase
3636
[ValidateNotNullOrEmpty]
3737
public string Name { get; set; }
3838

39+
/// <summary>
40+
/// Defines whether it is ok to skip the requesting of rule removal confirmation
41+
/// </summary>
42+
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
43+
public SwitchParameter Force { get; set; }
44+
3945
/// <summary>
4046
/// Defines whether the cmdlets will output the model object at the end of its execution
4147
/// </summary>
@@ -71,22 +77,18 @@ protected override IEnumerable<AzureSqlSyncGroupModel> PersistChanges(IEnumerabl
7177
}
7278

7379
/// <summary>
74-
/// Get the confirmation message when users want to remove a sync group
75-
/// </summary>
76-
/// <returns>The confirmation message</returns>
77-
protected override string GetConfirmActionProcessMessage()
78-
{
79-
return string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncGroupDescription, this.Name);
80-
}
81-
82-
/// <summary>
83-
/// Get resource id for confirmation message
80+
/// Entry point for the cmdlet
8481
/// </summary>
85-
/// <param name="model">The sync group that this cmdlet operates on</param>
86-
/// <returns>The resource id</returns>
87-
protected override string GetResourceId(IEnumerable<AzureSqlSyncGroupModel> model)
82+
public override void ExecuteCmdlet()
8883
{
89-
return string.Format("{0}.{1}", this.ServerName, this.DatabaseName);
84+
if (!Force.IsPresent && !ShouldProcess(
85+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncGroupDescription, this.Name),
86+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncGroupWarning, this.Name, this.DatabaseName),
87+
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption))
88+
{
89+
return;
90+
}
91+
base.ExecuteCmdlet();
9092
}
9193
}
9294
}

src/ResourceManager/Sql/Commands.Sql/Data Sync/Cmdlet/RemoveAzureSqlSyncMember.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class RemoveAzureSqlSyncMember : AzureSqlSyncMemberCmdletBase
3434
[ValidateNotNullOrEmpty]
3535
public string Name { get; set; }
3636

37+
/// <summary>
38+
/// Defines whether it is ok to skip the requesting of rule removal confirmation
39+
/// </summary>
40+
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
41+
public SwitchParameter Force { get; set; }
42+
3743
/// <summary>
3844
/// Defines whether the cmdlets will output the model object at the end of its execution
3945
/// </summary>
@@ -69,22 +75,18 @@ protected override IEnumerable<AzureSqlSyncMemberModel> PersistChanges(IEnumerab
6975
}
7076

7177
/// <summary>
72-
/// Get the confirmation message when users want to remove a sync member
73-
/// </summary>
74-
/// <returns>The confirmation message</returns>
75-
protected override string GetConfirmActionProcessMessage()
76-
{
77-
return string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncMemberDescription, this.Name, this.SyncGroupName);
78-
}
79-
80-
/// <summary>
81-
/// Get resource id for confirmation message
78+
/// Entry point for the cmdlet
8279
/// </summary>
83-
/// <param name="model">The sync member that this cmdlet operates on</param>
84-
/// <returns>The resource id</returns>
85-
protected override string GetResourceId(IEnumerable<AzureSqlSyncMemberModel> model)
80+
public override void ExecuteCmdlet()
8681
{
87-
return string.Format("{0}.{1}", this.ServerName, this.DatabaseName);
82+
if (!Force.IsPresent && !ShouldProcess(
83+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncMemberDescription, this.Name),
84+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncMemberWarning, this.Name, this.SyncGroupName),
85+
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption))
86+
{
87+
return;
88+
}
89+
base.ExecuteCmdlet();
8890
}
8991
}
9092
}

src/ResourceManager/Sql/Commands.Sql/Microsoft.Azure.Commands.Sql.dll-Help.xml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15507,6 +15507,14 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1550715507
<maml:uri /></dev:type>
1550815508
<dev:defaultValue>False</dev:defaultValue>
1550915509
</command:parameter>
15510+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15511+
<maml:Description><maml:para>Skip confirmation message for performing the action
15512+
</maml:para>
15513+
</maml:Description>
15514+
<dev:type><maml:name>SwitchParameter</maml:name>
15515+
<maml:uri /></dev:type>
15516+
<dev:defaultValue>False</dev:defaultValue>
15517+
</command:parameter>
1551015518
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>PassThru</maml:name>
1551115519
<maml:Description><maml:para>Defines Whether return the removed sync agent
1551215520
</maml:para>
@@ -15534,6 +15542,15 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1553415542
<maml:uri /></dev:type>
1553515543
<dev:defaultValue>False</dev:defaultValue>
1553615544
</command:parameter>
15545+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15546+
<maml:Description><maml:para>Skip confirmation message for performing the action
15547+
</maml:para>
15548+
</maml:Description>
15549+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
15550+
<dev:type><maml:name>SwitchParameter</maml:name>
15551+
<maml:uri /></dev:type>
15552+
<dev:defaultValue>False</dev:defaultValue>
15553+
</command:parameter>
1553715554
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="2" aliases="SyncAgentName"><maml:name>Name</maml:name>
1553815555
<maml:Description><maml:para>The sync agent name.
1553915556
</maml:para>
@@ -15663,6 +15680,14 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1566315680
<maml:uri /></dev:type>
1566415681
<dev:defaultValue>False</dev:defaultValue>
1566515682
</command:parameter>
15683+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15684+
<maml:Description><maml:para>Skip confirmation message for performing the action
15685+
</maml:para>
15686+
</maml:Description>
15687+
<dev:type><maml:name>SwitchParameter</maml:name>
15688+
<maml:uri /></dev:type>
15689+
<dev:defaultValue>False</dev:defaultValue>
15690+
</command:parameter>
1566615691
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>PassThru</maml:name>
1566715692
<maml:Description><maml:para>Defines Whether return the removed sync group
1566815693
</maml:para>
@@ -15699,6 +15724,15 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1569915724
<maml:uri /></dev:type>
1570015725
<dev:defaultValue>None</dev:defaultValue>
1570115726
</command:parameter>
15727+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15728+
<maml:Description><maml:para>Skip confirmation message for performing the action
15729+
</maml:para>
15730+
</maml:Description>
15731+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
15732+
<dev:type><maml:name>SwitchParameter</maml:name>
15733+
<maml:uri /></dev:type>
15734+
<dev:defaultValue>False</dev:defaultValue>
15735+
</command:parameter>
1570215736
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="3" aliases="SyncGroupName"><maml:name>Name</maml:name>
1570315737
<maml:Description><maml:para>The sync group name.
1570415738
</maml:para>
@@ -15767,7 +15801,7 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1576715801
<command:relatedLinks><maml:navigationLink><maml:linkText>New-AzureRmSqlSyncGroup</maml:linkText>
1576815802
<maml:uri></maml:uri>
1576915803
</maml:navigationLink>
15770-
<maml:navigationLink><maml:linkText>Set-AzureRmSqlSyncGroup</maml:linkText>
15804+
<maml:navigationLink><maml:linkText>Update-AzureRmSqlSyncGroup</maml:linkText>
1577115805
<maml:uri></maml:uri>
1577215806
</maml:navigationLink>
1577315807
<maml:navigationLink><maml:linkText>Get-AzureRmSqlSyncGroup</maml:linkText>
@@ -15831,6 +15865,14 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1583115865
<maml:uri /></dev:type>
1583215866
<dev:defaultValue>False</dev:defaultValue>
1583315867
</command:parameter>
15868+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15869+
<maml:Description><maml:para>Skip confirmation message for performing the action
15870+
</maml:para>
15871+
</maml:Description>
15872+
<dev:type><maml:name>SwitchParameter</maml:name>
15873+
<maml:uri /></dev:type>
15874+
<dev:defaultValue>False</dev:defaultValue>
15875+
</command:parameter>
1583415876
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="SyncMemberName"><maml:name>Name</maml:name>
1583515877
<maml:Description><maml:para>The sync member name.
1583615878
</maml:para>
@@ -15876,6 +15918,15 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1587615918
<maml:uri /></dev:type>
1587715919
<dev:defaultValue>None</dev:defaultValue>
1587815920
</command:parameter>
15921+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name>
15922+
<maml:Description><maml:para>Skip confirmation message for performing the action
15923+
</maml:para>
15924+
</maml:Description>
15925+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
15926+
<dev:type><maml:name>SwitchParameter</maml:name>
15927+
<maml:uri /></dev:type>
15928+
<dev:defaultValue>False</dev:defaultValue>
15929+
</command:parameter>
1587915930
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="SyncMemberName"><maml:name>Name</maml:name>
1588015931
<maml:Description><maml:para>The sync member name.
1588115932
</maml:para>
@@ -15953,7 +16004,7 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d
1595316004
<command:relatedLinks><maml:navigationLink><maml:linkText>New-AzureRmSqlSyncMember</maml:linkText>
1595416005
<maml:uri></maml:uri>
1595516006
</maml:navigationLink>
15956-
<maml:navigationLink><maml:linkText>Set-AzureRmSqlSyncMember</maml:linkText>
16007+
<maml:navigationLink><maml:linkText>Update-AzureRmSqlSyncMember</maml:linkText>
1595716008
<maml:uri></maml:uri>
1595816009
</maml:navigationLink>
1595916010
<maml:navigationLink><maml:linkText>Get-AzureRmSqlSyncMember</maml:linkText>

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.Designer.cs

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346
<value>Sync Group with name: ‘{0}' already exists in database '{1}'.</value>
347347
</data>
348348
<data name="RemoveAzureSqlSyncMemberDescription" xml:space="preserve">
349-
<value>Permanently removing Azure Sql Sync Member '{0}' on Sync Group '{1}'.</value>
349+
<value>Permanently removing Azure Sql Sync Member '{0}'.</value>
350350
</data>
351351
<data name="SyncMemberNameExists" xml:space="preserve">
352352
<value>Sync Member with name: ‘{0}' already exists in Sync Group '{1}'.</value>
@@ -357,4 +357,13 @@
357357
<data name="SyncAgentNameExists" xml:space="preserve">
358358
<value>Sync Agent with name: ‘{0}' already exists in Resource Group '{1}'.</value>
359359
</data>
360+
<data name="RemoveAzureSqlSyncAgentWarning" xml:space="preserve">
361+
<value>Are you sure you want to remove the Sync Agent '{0}' for Resource Group '{1}' ?</value>
362+
</data>
363+
<data name="RemoveAzureSqlSyncGroupWarning" xml:space="preserve">
364+
<value>Are you sure you want to remove the Sync Group '{0}' for database '{1}'?</value>
365+
</data>
366+
<data name="RemoveAzureSqlSyncMemberWarning" xml:space="preserve">
367+
<value>Are you sure you want to remove the Sync Member '{0}' for Sync Group '{1}'?</value>
368+
</data>
360369
</root>

src/ResourceManager/Sql/Commands.Sql/help/Remove-AzureRmSqlSyncAgent.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Removes an Azure SQL Sync Agent.
1212
## SYNTAX
1313

1414
```
15-
Remove-AzureRmSqlSyncAgent [-Name] <String> [-PassThru] [-ServerName] <String> [-ResourceGroupName] <String>
16-
[-WhatIf] [-Confirm]
15+
Remove-AzureRmSqlSyncAgent [-Name] <String> [-Force] [-PassThru] [-ServerName] <String>
16+
[-ResourceGroupName] <String> [-WhatIf] [-Confirm]
1717
```
1818

1919
## DESCRIPTION
@@ -45,6 +45,21 @@ Accept pipeline input: False
4545
Accept wildcard characters: False
4646
```
4747
48+
### -Force
49+
Skip confirmation message for performing the action
50+
51+
```yaml
52+
Type: SwitchParameter
53+
Parameter Sets: (All)
54+
Aliases:
55+
56+
Required: False
57+
Position: Named
58+
Default value: None
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
4863
### -Name
4964
The sync agent name.
5065

0 commit comments

Comments
 (0)