Skip to content

Commit 8eaa8c9

Browse files
committed
Take lists of files with elements to exclude, instead of directly passing list of elements to exclude.
1 parent 92f306c commit 8eaa8c9

File tree

6 files changed

+125
-78
lines changed

6 files changed

+125
-78
lines changed

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff.Tool/GenAPIDiffConfigurationBinder.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ internal class GenAPIDiffConfigurationBinder : BinderBase<DiffConfiguration>
1717
private readonly Option<string> _optionBeforeFriendlyName;
1818
private readonly Option<string> _optionAfterFriendlyName;
1919
private readonly Option<string> _optionTableOfContentsTitle;
20-
private readonly Option<string[]?> _optionAssembliesToExclude;
21-
private readonly Option<string[]?> _optionAttributesToExclude;
22-
private readonly Option<string[]?> _optionApisToExclude;
20+
private readonly Option<FileInfo[]?> _optionFilesWithAssembliesToExclude;
21+
private readonly Option<FileInfo[]?> _optionFilesWithAttributesToExclude;
22+
private readonly Option<FileInfo[]?> _optionFilesWithApisToExclude;
2323
private readonly Option<bool> _optionAddPartialModifier;
2424
private readonly Option<bool> _optionAttachDebugger;
2525

@@ -31,9 +31,9 @@ internal GenAPIDiffConfigurationBinder(Option<string> optionBeforeAssembliesFold
3131
Option<string> optionBeforeFriendlyName,
3232
Option<string> optionAfterFriendlyName,
3333
Option<string> optionTableOfContentsTitle,
34-
Option<string[]?> optionAssembliesToExclude,
35-
Option<string[]?> optionAttributesToExclude,
36-
Option<string[]?> optionApisToExclude,
34+
Option<FileInfo[]?> optionFilesWithAssembliesToExclude,
35+
Option<FileInfo[]?> optionFilesWithAttributesToExclude,
36+
Option<FileInfo[]?> optionFilesWithApisToExclude,
3737
Option<bool> optionAddPartialModifier,
3838
Option<bool> optionAttachDebugger)
3939
{
@@ -45,9 +45,9 @@ internal GenAPIDiffConfigurationBinder(Option<string> optionBeforeAssembliesFold
4545
_optionBeforeFriendlyName = optionBeforeFriendlyName;
4646
_optionAfterFriendlyName = optionAfterFriendlyName;
4747
_optionTableOfContentsTitle = optionTableOfContentsTitle;
48-
_optionAssembliesToExclude = optionAssembliesToExclude;
49-
_optionAttributesToExclude = optionAttributesToExclude;
50-
_optionApisToExclude = optionApisToExclude;
48+
_optionFilesWithAssembliesToExclude = optionFilesWithAssembliesToExclude;
49+
_optionFilesWithAttributesToExclude = optionFilesWithAttributesToExclude;
50+
_optionFilesWithApisToExclude = optionFilesWithApisToExclude;
5151
_optionAddPartialModifier = optionAddPartialModifier;
5252
_optionAttachDebugger = optionAttachDebugger;
5353
}
@@ -62,9 +62,9 @@ protected override DiffConfiguration GetBoundValue(BindingContext bindingContext
6262
BeforeFriendlyName: bindingContext.ParseResult.GetValueForOption(_optionBeforeFriendlyName) ?? throw new NullReferenceException("Null before friendly name"),
6363
AfterFriendlyName: bindingContext.ParseResult.GetValueForOption(_optionAfterFriendlyName) ?? throw new NullReferenceException("Null after friendly name"),
6464
TableOfContentsTitle: bindingContext.ParseResult.GetValueForOption(_optionTableOfContentsTitle) ?? throw new NullReferenceException("Null table of contents title"),
65-
AssembliesToExclude: bindingContext.ParseResult.GetValueForOption(_optionAssembliesToExclude),
66-
AttributesToExclude: bindingContext.ParseResult.GetValueForOption(_optionAttributesToExclude),
67-
ApisToExclude: bindingContext.ParseResult.GetValueForOption(_optionApisToExclude),
65+
FilesWithAssembliesToExclude: bindingContext.ParseResult.GetValueForOption(_optionFilesWithAssembliesToExclude),
66+
FilesWithAttributesToExclude: bindingContext.ParseResult.GetValueForOption(_optionFilesWithAttributesToExclude),
67+
FilesWithApisToExclude: bindingContext.ParseResult.GetValueForOption(_optionFilesWithApisToExclude),
6868
AddPartialModifier: bindingContext.ParseResult.GetValueForOption(_optionAddPartialModifier),
6969
AttachDebugger: bindingContext.ParseResult.GetValueForOption(_optionAttachDebugger)
7070
);

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff.Tool/Program.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ public static async Task Main(string[] args)
7373
IsRequired = true
7474
};
7575

76-
Option<string[]?> optionAssembliesToExclude = new(["--assembliesToExclude", "-eas"], () => null)
76+
Option<FileInfo[]?> optionFilesWithAssembliesToExclude = new(["--assembliesToExclude", "-eas"], () => null)
7777
{
78-
Description = "Assemblies from both before and after to exclude from the diff.",
78+
Description = "An optional array of filepaths, each containing a list of assemblies that should be excluded from the diff. Each file should contain one assembly name per line, with no extensions.",
7979
Arity = ArgumentArity.ZeroOrMore,
8080
IsRequired = false,
8181
};
8282

83-
Option<string[]?> optionAttributesToExclude = new(["--attributesToExclude", "-eattrs"], () => null)
83+
Option<FileInfo[]?> optionFilesWithAttributesToExclude = new(["--attributesToExclude", "-eattrs"], () => null)
8484
{
85-
Description = "Attributes to exclude from the diff.",
85+
Description = "An optional array of filepaths, each containing a list of attributes to exclude from the diff. Each file should contain one API full name per line.",
8686
Arity = ArgumentArity.ZeroOrMore,
8787
IsRequired = false
8888
};
8989

90-
Option<string[]?> optionApisToExclude = new(["--apisToExclude", "-eapis"], () => null)
90+
Option<FileInfo[]?> optionFilesWithApisToExclude = new(["--apisToExclude", "-eapis"], () => null)
9191
{
92-
Description = "APIs to exclude from the diff.",
92+
Description = "An optional array of filepaths, each containing a list of APIs to exclude from the diff. Each file should contain one API full name per line.",
9393
Arity = ArgumentArity.ZeroOrMore,
9494
IsRequired = false
9595
};
@@ -113,9 +113,9 @@ public static async Task Main(string[] args)
113113
rootCommand.Add(optionBeforeFriendlyName);
114114
rootCommand.Add(optionAfterFriendlyName);
115115
rootCommand.Add(optionTableOfContentsTitle);
116-
rootCommand.Add(optionAssembliesToExclude);
117-
rootCommand.Add(optionAttributesToExclude);
118-
rootCommand.Add(optionApisToExclude);
116+
rootCommand.Add(optionFilesWithAssembliesToExclude);
117+
rootCommand.Add(optionFilesWithAttributesToExclude);
118+
rootCommand.Add(optionFilesWithApisToExclude);
119119
rootCommand.Add(optionAddPartialModifier);
120120
rootCommand.Add(optionAttachDebugger);
121121

@@ -127,9 +127,9 @@ public static async Task Main(string[] args)
127127
optionBeforeFriendlyName,
128128
optionAfterFriendlyName,
129129
optionTableOfContentsTitle,
130-
optionAssembliesToExclude,
131-
optionAttributesToExclude,
132-
optionApisToExclude,
130+
optionFilesWithAssembliesToExclude,
131+
optionFilesWithAttributesToExclude,
132+
optionFilesWithApisToExclude,
133133
optionAddPartialModifier,
134134
optionAttachDebugger);
135135

@@ -141,9 +141,9 @@ private static Task HandleCommandAsync(DiffConfiguration diffConfig)
141141
{
142142
var log = new ConsoleLog(MessageImportance.Normal);
143143

144-
string assembliesToExclude = string.Join(", ", diffConfig.AssembliesToExclude ?? []);
145-
string attributesToExclude = string.Join(", ", diffConfig.AttributesToExclude ?? []);
146-
string apisToExclude = string.Join(", ", diffConfig.ApisToExclude ?? []);
144+
string assembliesToExclude = string.Join(", ", diffConfig.FilesWithAssembliesToExclude?.Select(a => a.FullName) ?? []);
145+
string attributesToExclude = string.Join(", ", diffConfig.FilesWithAttributesToExclude?.Select(a => a.FullName) ?? []);
146+
string apisToExclude = string.Join(", ", diffConfig.FilesWithApisToExclude?.Select(a => a.FullName) ?? []);
147147

148148
// Custom ordering to match help menu.
149149
log.LogMessage("Selected options:");
@@ -152,9 +152,9 @@ private static Task HandleCommandAsync(DiffConfiguration diffConfig)
152152
log.LogMessage($" - 'Before' reference assemblies: {diffConfig.BeforeAssemblyReferencesFolderPath}");
153153
log.LogMessage($" - 'After' reference assemblies: {diffConfig.AfterAssemblyReferencesFolderPath}");
154154
log.LogMessage($" - Output: {diffConfig.OutputFolderPath}");
155-
log.LogMessage($" - Assemblies to exclude: {assembliesToExclude}");
156-
log.LogMessage($" - Attributes to exclude: {attributesToExclude}");
157-
log.LogMessage($" - APIs to exclude: {apisToExclude}");
155+
log.LogMessage($" - Files with assemblies to exclude: {assembliesToExclude}");
156+
log.LogMessage($" - Files with attributes to exclude: {attributesToExclude}");
157+
log.LogMessage($" - Files with APIs to exclude: {apisToExclude}");
158158
log.LogMessage($" - 'Before' friendly name: {diffConfig.BeforeFriendlyName}");
159159
log.LogMessage($" - 'After' friendly name: {diffConfig.AfterFriendlyName}");
160160
log.LogMessage($" - Table of contents title: {diffConfig.TableOfContentsTitle}");
@@ -176,9 +176,9 @@ private static Task HandleCommandAsync(DiffConfiguration diffConfig)
176176
diffConfig.BeforeFriendlyName,
177177
diffConfig.AfterFriendlyName,
178178
diffConfig.TableOfContentsTitle,
179-
diffConfig.AssembliesToExclude,
180-
diffConfig.AttributesToExclude,
181-
diffConfig.ApisToExclude,
179+
diffConfig.FilesWithAssembliesToExclude,
180+
diffConfig.FilesWithAttributesToExclude,
181+
diffConfig.FilesWithApisToExclude,
182182
diffConfig.AddPartialModifier,
183183
writeToDisk: true,
184184
diagnosticOptions: null // TODO: If needed, add CLI option to pass specific diagnostic options

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/DiffConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public record DiffConfiguration(
1515
string BeforeFriendlyName,
1616
string AfterFriendlyName,
1717
string TableOfContentsTitle,
18-
string[]? AssembliesToExclude,
19-
string[]? AttributesToExclude,
20-
string[]? ApisToExclude,
18+
FileInfo[]? FilesWithAssembliesToExclude,
19+
FileInfo[]? FilesWithAttributesToExclude,
20+
FileInfo[]? FilesWithApisToExclude,
2121
bool AddPartialModifier,
2222
bool AttachDebugger
2323
);

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/DiffGeneratorFactory.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static class DiffGeneratorFactory
4242
/// <param name="beforeFriendlyName">The friendly name for the assemblies before the change.</param>
4343
/// <param name="afterFriendlyName">The friendly name for the assemblies after the change.</param>
4444
/// <param name="tableOfContentsTitle">The title for the table of contents in the generated diff.</param>
45-
/// <param name="assembliesToExclude">An optional list of assemblies to avoid showing in the diff. If <see langword="null"/>, no assemblies are excluded.</param>
46-
/// <param name="attributesToExclude">An optional list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
47-
/// <param name="apisToExclude">An optional list of APIs to avoid showing in the diff.</param>
45+
/// <param name="filesWithAssembliesToExclude">An optional array of filepaths each containing a list of assemblies to avoid showing in the diff. If <see langword="null"/>, no assemblies are excluded.</param>
46+
/// <param name="filesWithAttributesToExclude">An optional array of filepaths each containing a list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
47+
/// <param name="filesWithApisToExclude">An optional array of filepaths each containing a list of APIs to avoid showing in the diff.</param>
4848
/// <param name="addPartialModifier">Indicates whether to add the partial modifier to types.</param>
4949
/// <param name="writeToDisk">If <see langword="true"/>, when calling <see cref="IDiffGenerator.RunAsync"/>, the generated markdown files get written to disk, and no item is added to the <see cref="IDiffGenerator.RunAsync"/> dictionary. If <see langword="false"/>, when calling <see cref="IDiffGenerator.RunAsync"/>, the generated markdown files get added to the <see cref="IDiffGenerator.RunAsync"/> dictionary (with the file path as the dictionary key) and none of them is written to disk. This is meant for testing purposes.</param>
5050
/// <param name="diagnosticOptions">An optional list of diagnostic options to use when generating the diff.</param>
@@ -59,9 +59,9 @@ public static IDiffGenerator Create(ILog log,
5959
string beforeFriendlyName,
6060
string afterFriendlyName,
6161
string tableOfContentsTitle,
62-
string[]? assembliesToExclude,
63-
string[]? attributesToExclude,
64-
string[]? apisToExclude,
62+
FileInfo[]? filesWithAssembliesToExclude,
63+
FileInfo[]? filesWithAttributesToExclude,
64+
FileInfo[]? filesWithApisToExclude,
6565
bool addPartialModifier,
6666
bool writeToDisk,
6767
IEnumerable<KeyValuePair<string, ReportDiagnostic>>? diagnosticOptions = null)
@@ -75,9 +75,9 @@ public static IDiffGenerator Create(ILog log,
7575
beforeFriendlyName,
7676
afterFriendlyName,
7777
tableOfContentsTitle,
78-
assembliesToExclude,
79-
attributesToExclude,
80-
apisToExclude,
78+
filesWithAssembliesToExclude,
79+
filesWithAttributesToExclude,
80+
filesWithApisToExclude,
8181
addPartialModifier,
8282
writeToDisk,
8383
diagnosticOptions);

0 commit comments

Comments
 (0)