@@ -18,96 +18,96 @@ public static class Program
18
18
19
19
public static async Task Main ( string [ ] args )
20
20
{
21
- RootCommand rootCommand = new ( "genapidiff " ) ;
21
+ RootCommand rootCommand = new ( "ApiDiff - Tool for generating a markdown diff of two different versions of the same assembly. " ) ;
22
22
23
- Option < string > optionBeforeAssembliesFolderPath = new ( name : "" , aliases : [ " --before", "-b" ] )
23
+ Option < string > optionBeforeAssembliesFolderPath = new ( " --before", "-b" )
24
24
{
25
25
Description = "The path to the folder containing the old (before) assemblies to be included in the diff." ,
26
26
Arity = ArgumentArity . ExactlyOne ,
27
27
Required = true
28
28
} ;
29
29
30
- Option < string > optionBeforeRefAssembliesFolderPath = new ( name : "" , aliases : [ " --refbefore", "-rb" ] )
30
+ Option < string > optionBeforeRefAssembliesFolderPath = new ( " --refbefore", "-rb" )
31
31
{
32
32
Description = "The path to the folder containing the references required by old (before) assemblies, not to be included in the diff." ,
33
33
Arity = ArgumentArity . ExactlyOne ,
34
34
Required = false
35
35
} ;
36
36
37
- Option < string > optionAfterAssembliesFolderPath = new ( name : "" , aliases : [ " --after", "-a" ] )
37
+ Option < string > optionAfterAssembliesFolderPath = new ( " --after", "-a" )
38
38
{
39
39
Description = "The path to the folder containing the new (after) assemblies to be included in the diff." ,
40
40
Arity = ArgumentArity . ExactlyOne ,
41
41
Required = true
42
42
} ;
43
43
44
- Option < string > optionAfterRefAssembliesFolderPath = new ( name : "" , aliases : [ " --refafter", "-ra" ] )
44
+ Option < string > optionAfterRefAssembliesFolderPath = new ( " --refafter", "-ra" )
45
45
{
46
46
Description = "The path to the folder containing references required by the new (after) reference assemblies, not to be included in the diff." ,
47
47
Arity = ArgumentArity . ExactlyOne ,
48
48
Required = false
49
49
} ;
50
50
51
- Option < string > optionOutputFolderPath = new ( name : "" , aliases : [ " --output", "-o" ] )
51
+ Option < string > optionOutputFolderPath = new ( " --output", "-o" )
52
52
{
53
53
Description = "The path to the output folder." ,
54
54
Arity = ArgumentArity . ExactlyOne ,
55
55
Required = true
56
56
} ;
57
57
58
- Option < string > optionBeforeFriendlyName = new ( name : "" , aliases : [ " --beforeFriendlyName", "-bfn" ] )
58
+ Option < string > optionBeforeFriendlyName = new ( " --beforeFriendlyName", "-bfn" )
59
59
{
60
60
Description = "The friendly name to describe the 'before' assembly." ,
61
61
Arity = ArgumentArity . ExactlyOne ,
62
62
Required = true
63
63
} ;
64
64
65
- Option < string > optionAfterFriendlyName = new ( name : "" , aliases : [ " --afterFriendlyName", "-afn" ] )
65
+ Option < string > optionAfterFriendlyName = new ( " --afterFriendlyName", "-afn" )
66
66
{
67
67
Description = "The friendly name to describe the 'after' assembly." ,
68
68
Arity = ArgumentArity . ExactlyOne ,
69
69
Required = true
70
70
} ;
71
71
72
- Option < string > optionTableOfContentsTitle = new ( name : "" , aliases : [ " --tableOfContentsTitle", "-tc" ] )
72
+ Option < string > optionTableOfContentsTitle = new ( " --tableOfContentsTitle", "-tc" )
73
73
{
74
74
Description = $ "The optional title of the markdown table of contents file that is placed in the output folder.",
75
- Arity = ArgumentArity . ZeroOrMore ,
75
+ Arity = ArgumentArity . ExactlyOne ,
76
76
Required = false ,
77
77
DefaultValueFactory = _ => "api_diff"
78
78
} ;
79
79
80
- Option < FileInfo [ ] ? > optionFilesWithAssembliesToExclude = new ( name : "" , aliases : [ " --assembliesToExclude", "-eas" ] )
80
+ Option < FileInfo [ ] ? > optionFilesWithAssembliesToExclude = new ( " --assembliesToExclude", "-eas" )
81
81
{
82
82
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." ,
83
83
Arity = ArgumentArity . ZeroOrMore ,
84
84
Required = false ,
85
85
DefaultValueFactory = _ => null
86
86
} ;
87
87
88
- Option < FileInfo [ ] ? > optionFilesWithAttributesToExclude = new ( name : "" , aliases : [ " --attributesToExclude", "-eattrs" ] )
88
+ Option < FileInfo [ ] ? > optionFilesWithAttributesToExclude = new ( " --attributesToExclude", "-eattrs" )
89
89
{
90
90
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. You can either modify the default file '{ AttributesToExcludeDefaultFileName } ' to add your own attributes, or include additional files using this command line option.",
91
91
Arity = ArgumentArity . ZeroOrMore ,
92
92
Required = false ,
93
93
DefaultValueFactory = _ => [ new FileInfo ( AttributesToExcludeDefaultFileName ) ]
94
94
} ;
95
95
96
- Option < FileInfo [ ] ? > optionFilesWithApisToExclude = new ( name : "" , aliases : [ " --apisToExclude", "-eapis" ] )
96
+ Option < FileInfo [ ] ? > optionFilesWithApisToExclude = new ( " --apisToExclude", "-eapis" )
97
97
{
98
98
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." ,
99
99
Arity = ArgumentArity . ZeroOrMore ,
100
100
Required = false ,
101
101
DefaultValueFactory = _ => null
102
102
} ;
103
103
104
- Option < bool > optionAddPartialModifier = new ( name : "" , aliases : [ " --addPartialModifier", "-apm" ] )
104
+ Option < bool > optionAddPartialModifier = new ( " --addPartialModifier", "-apm" )
105
105
{
106
106
Description = "Add the 'partial' modifier to types." ,
107
107
DefaultValueFactory = _ => false
108
108
} ;
109
109
110
- Option < bool > optionAttachDebugger = new ( name : "" , aliases : [ " --attachDebugger", "-d" ] )
110
+ Option < bool > optionAttachDebugger = new ( " --attachDebugger", "-d" )
111
111
{
112
112
Description = "Stops the tool at startup, prints the process ID and waits for a debugger to attach." ,
113
113
DefaultValueFactory = _ => false
@@ -128,9 +128,9 @@ public static async Task Main(string[] args)
128
128
rootCommand . Options . Add ( optionAddPartialModifier ) ;
129
129
rootCommand . Options . Add ( optionAttachDebugger ) ;
130
130
131
- rootCommand . SetAction ( async ( ParseResult result ) =>
131
+ rootCommand . SetAction ( async ( ParseResult result , CancellationToken cancellationToken ) =>
132
132
{
133
- DiffConfiguration c = new (
133
+ DiffConfiguration diffConfig = new (
134
134
BeforeAssembliesFolderPath : result . GetValue ( optionBeforeAssembliesFolderPath ) ?? throw new NullReferenceException ( "Null before assemblies directory" ) ,
135
135
BeforeAssemblyReferencesFolderPath : result . GetValue ( optionBeforeRefAssembliesFolderPath ) ,
136
136
AfterAssembliesFolderPath : result . GetValue ( optionAfterAssembliesFolderPath ) ?? throw new NullReferenceException ( "Null after assemblies directory" ) ,
@@ -145,13 +145,15 @@ public static async Task Main(string[] args)
145
145
AddPartialModifier : result . GetValue ( optionAddPartialModifier ) ,
146
146
AttachDebugger : result . GetValue ( optionAttachDebugger )
147
147
) ;
148
- await HandleCommandAsync ( c ) . ConfigureAwait ( false ) ;
148
+ await HandleCommandAsync ( diffConfig , cancellationToken ) . ConfigureAwait ( false ) ;
149
149
} ) ;
150
150
await rootCommand . Parse ( args ) . InvokeAsync ( ) ;
151
151
}
152
152
153
- private static Task HandleCommandAsync ( DiffConfiguration diffConfig )
153
+ private static Task HandleCommandAsync ( DiffConfiguration diffConfig , CancellationToken cancellationToken = default )
154
154
{
155
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
156
+
155
157
var log = new ConsoleLog ( MessageImportance . Normal ) ;
156
158
157
159
string assembliesToExclude = string . Join ( ", " , diffConfig . FilesWithAssembliesToExclude ? . Select ( a => a . FullName ) ?? [ ] ) ;
@@ -197,7 +199,7 @@ private static Task HandleCommandAsync(DiffConfiguration diffConfig)
197
199
diagnosticOptions : null // TODO: If needed, add CLI option to pass specific diagnostic options
198
200
) ;
199
201
200
- return diffGenerator . RunAsync ( ) ;
202
+ return diffGenerator . RunAsync ( cancellationToken ) ;
201
203
}
202
204
203
205
private static void WaitForDebugger ( )
0 commit comments