Skip to content

Commit b1b6e80

Browse files
authored
Add module name to breaking changes (#405)
* Add module name to breaking changes * format and refactor * update from to in
1 parent 6d459c2 commit b1b6e80

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

src/Common/CustomAttributes/BreakingChangeAttributeHelper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static void ProcessCustomAttributesAtRuntime(Type type, InvocationInfo in
8989

9090
foreach (GenericBreakingChangeWithVersionAttribute attribute in attributes)
9191
{
92-
attribute.PrintCustomAttributeInfo(type, false, appendBreakingChangeInfo);
92+
attribute.PrintCustomAttributeInfo(type, false, invocationInfo?.MyCommand?.ModuleName, appendBreakingChangeInfo);
9393
}
9494

9595
appendBreakingChangeInfo(string.Format(Resources.BreakingChangesAttributesFooterMessage, BREAKING_CHANGE_ATTRIBUTE_INFORMATION_LINK));
@@ -117,6 +117,20 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)
117117
return messages;
118118
}
119119

120+
public static List<string> GetBreakingChangeMessagesForType(Type type, InvocationInfo invocationInfo)
121+
{
122+
List<string> messages = new List<string>();
123+
124+
//This is used as a migration guide, we need to process all properties/fields, moreover at this point of time we do not have a list of all the
125+
//bound params anyways
126+
foreach (GenericBreakingChangeWithVersionAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
127+
{
128+
messages.Add(attribute.GetBreakingChangeTextFromAttribute(type, true, invocationInfo?.MyCommand?.ModuleName));
129+
}
130+
131+
return messages;
132+
}
133+
120134
/**
121135
* This function takes in a Type (expected to be a derevative of the AzurePSCmdlet)
122136
* And returns all the deprecation attributes attached to it

src/Common/CustomAttributes/GenericBreakingChangeWithVersionAttribute.cs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ public DateTime getInEffectByDate()
7979
* We get the cmdlet name from the passed in Type (it is expected to have the Cmdlet attribute decorated on the class)
8080
*/
8181
public string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName)
82+
{
83+
return GetBreakingChangeTextFromAttributeInternal(type, withCmdletName, null);
84+
}
85+
86+
internal string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName, String moduleName)
87+
{
88+
return GetBreakingChangeTextFromAttributeInternal(type, withCmdletName, moduleName);
89+
}
90+
91+
private string GetBreakingChangeTextFromAttributeInternal(Type type, bool withCmdletName, String moduleName)
8292
{
8393
StringBuilder breakingChangeMessage = new StringBuilder();
8494

@@ -104,7 +114,14 @@ public string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName)
104114

105115
if (!string.IsNullOrWhiteSpace(DeprecateByVersion))
106116
{
107-
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
117+
if (moduleName != null)
118+
{
119+
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByVersion2, moduleName, this.DeprecateByVersion));
120+
}
121+
else
122+
{
123+
breakingChangeMessage.Append(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
124+
}
108125
}
109126

110127
if (!string.IsNullOrWhiteSpace(OldWay) && !string.IsNullOrWhiteSpace(NewWay))
@@ -123,6 +140,16 @@ public string GetBreakingChangeTextFromAttribute(Type type, bool withCmdletName)
123140
* We get the cmdlet name from the passed in Type (it is expected to have the Cmdlet attribute decorated on the class)
124141
* */
125142
public void PrintCustomAttributeInfo(Type type, bool withCmdletName, Action<string> writeOutput)
143+
{
144+
PrintCustomAttributeInfoInternal(type, withCmdletName, null, writeOutput);
145+
}
146+
147+
internal void PrintCustomAttributeInfo(Type type, bool withCmdletName, String moduleName, Action<string> writeOutput)
148+
{
149+
PrintCustomAttributeInfoInternal(type, withCmdletName, moduleName, writeOutput);
150+
}
151+
152+
private void PrintCustomAttributeInfoInternal(Type type, bool withCmdletName, String moduleName, Action<string> writeOutput)
126153
{
127154
if (!withCmdletName)
128155
{
@@ -146,11 +173,18 @@ public void PrintCustomAttributeInfo(Type type, bool withCmdletName, Action<stri
146173
{
147174
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEffectByDate.ToShortDateString()));
148175
}
149-
176+
150177
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByAzVersion, this.DeprecateByAzVersion));
151-
152-
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
153-
178+
179+
if (moduleName != null)
180+
{
181+
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByVersion2, moduleName, this.DeprecateByVersion));
182+
}
183+
else
184+
{
185+
writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
186+
}
187+
154188
if (OldWay != null && NewWay != null)
155189
{
156190
writeOutput(string.Format(Resources.BreakingChangesAttributesUsageChangeMessageConsole, OldWay, NewWay));

src/Common/Properties/Resources.Designer.cs

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Properties/Resources.resx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ Use the Enable-AzureDataCollection cmdlet to turn the feature On. The cmdlet can
17021702
</data>
17031703
<data name="BreakingChangesAttributesInEffectByVersion" xml:space="preserve">
17041704
<value>
1705-
- The change is expected to take effect from version : '{0}'</value>
1705+
- The change is expected to take effect in version : '{0}'</value>
17061706
</data>
17071707
<data name="BreakingChangesAttributesUsageChangeMessage" xml:space="preserve">
17081708
<value>```powershell
@@ -1737,7 +1737,7 @@ Note : Go to {0} for steps to suppress this breaking change warning, and other i
17371737
</data>
17381738
<data name="BreakingChangesAttributesInEffectByAzVersion" xml:space="preserve">
17391739
<value>
1740-
- The change is expected to take effect from Az version : '{0}'</value>
1740+
- The change is expected to take effect in Az version : '{0}'</value>
17411741
</data>
17421742
<data name="PreviewCmdletETAMessage" xml:space="preserve">
17431743
<value> The estimated generally available date is '{0}'.</value>
@@ -1753,4 +1753,8 @@ Note : Go to {0} for steps to suppress this breaking change warning, and other i
17531753
{3} {4} -WhatIf -- Simulate updating your Az modules.
17541754
{3} {4} -- Update your Az modules.</value>
17551755
</data>
1756+
<data name="BreakingChangesAttributesInEffectByVersion2" xml:space="preserve">
1757+
<value>
1758+
- The change is expected to take effect in {0} version : '{1}'</value>
1759+
</data>
17561760
</root>

0 commit comments

Comments
 (0)