2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . CommandLine ;
5
+ using System . ComponentModel ;
5
6
using System . Diagnostics ;
6
7
using Microsoft . DotNet . ApiSymbolExtensions . Logging ;
7
8
@@ -17,124 +18,134 @@ public static async Task Main(string[] args)
17
18
{
18
19
RootCommand rootCommand = new ( "genapidiff" ) ;
19
20
20
- Option < string > optionBeforeAssembliesFolderPath = new ( [ "--before" , "-b" ] )
21
+ Option < string > optionBeforeAssembliesFolderPath = new ( name : "" , aliases : [ "--before" , "-b" ] )
21
22
{
22
23
Description = "The path to the folder containing the old (before) assemblies to be included in the diff." ,
23
24
Arity = ArgumentArity . ExactlyOne ,
24
- IsRequired = true
25
+ Required = true
25
26
} ;
26
27
27
- Option < string > optionBeforeRefAssembliesFolderPath = new ( [ "--refbefore" , "-rb" ] )
28
+ Option < string > optionBeforeRefAssembliesFolderPath = new ( name : "" , aliases : [ "--refbefore" , "-rb" ] )
28
29
{
29
30
Description = "The path to the folder containing the references required by old (before) assemblies, not to be included in the diff." ,
30
31
Arity = ArgumentArity . ExactlyOne ,
31
- IsRequired = false
32
+ Required = false
32
33
} ;
33
34
34
- Option < string > optionAfterAssembliesFolderPath = new ( [ "--after" , "-a" ] )
35
+ Option < string > optionAfterAssembliesFolderPath = new ( name : "" , aliases : [ "--after" , "-a" ] )
35
36
{
36
37
Description = "The path to the folder containing the new (after) assemblies to be included in the diff." ,
37
38
Arity = ArgumentArity . ExactlyOne ,
38
- IsRequired = true
39
+ Required = true
39
40
} ;
40
41
41
- Option < string > optionAfterRefAssembliesFolderPath = new ( [ "--refafter" , "-ra" ] )
42
+ Option < string > optionAfterRefAssembliesFolderPath = new ( name : "" , aliases : [ "--refafter" , "-ra" ] )
42
43
{
43
44
Description = "The path to the folder containing references required by the new (after) reference assemblies, not to be included in the diff." ,
44
45
Arity = ArgumentArity . ExactlyOne ,
45
- IsRequired = false
46
+ Required = false
46
47
} ;
47
48
48
- Option < string > optionOutputFolderPath = new ( [ "--output" , "-o" ] )
49
+ Option < string > optionOutputFolderPath = new ( name : "" , aliases : [ "--output" , "-o" ] )
49
50
{
50
51
Description = "The path to the output folder." ,
51
52
Arity = ArgumentArity . ExactlyOne ,
52
- IsRequired = true
53
+ Required = true
53
54
} ;
54
55
55
- Option < string > optionBeforeFriendlyName = new ( [ "--beforeFriendlyName" , "-bfn" ] )
56
+ Option < string > optionBeforeFriendlyName = new ( name : "" , aliases : [ "--beforeFriendlyName" , "-bfn" ] )
56
57
{
57
58
Description = "The friendly name to describe the 'before' assembly." ,
58
59
Arity = ArgumentArity . ExactlyOne ,
59
- IsRequired = true
60
+ Required = true
60
61
} ;
61
62
62
- Option < string > optionAfterFriendlyName = new ( [ "--afterFriendlyName" , "-afn" ] )
63
+ Option < string > optionAfterFriendlyName = new ( name : "" , aliases : [ "--afterFriendlyName" , "-afn" ] )
63
64
{
64
65
Description = "The friendly name to describe the 'after' assembly." ,
65
66
Arity = ArgumentArity . ExactlyOne ,
66
- IsRequired = true
67
+ Required = true
67
68
} ;
68
69
69
- Option < string > optionTableOfContentsTitle = new ( [ "--tableOfContentsTitle" , "-tc" ] , ( ) => "api_diff" )
70
+ Option < string > optionTableOfContentsTitle = new ( name : "" , aliases : [ "--tableOfContentsTitle" , "-tc" ] )
70
71
{
71
72
Description = $ "The optional title of the markdown table of contents file that is placed in the output folder.",
72
73
Arity = ArgumentArity . ZeroOrMore ,
73
- IsRequired = true
74
+ Required = true ,
75
+ DefaultValueFactory = _ => "api_diff"
74
76
} ;
75
77
76
- Option < FileInfo [ ] ? > optionFilesWithAssembliesToExclude = new ( [ "--assembliesToExclude" , "-eas" ] , ( ) => null )
78
+ Option < FileInfo [ ] ? > optionFilesWithAssembliesToExclude = new ( name : "" , aliases : [ "--assembliesToExclude" , "-eas" ] )
77
79
{
78
80
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." ,
79
81
Arity = ArgumentArity . ZeroOrMore ,
80
- IsRequired = false ,
82
+ Required = false ,
83
+ DefaultValueFactory = _ => null
81
84
} ;
82
85
83
- Option < FileInfo [ ] ? > optionFilesWithAttributesToExclude = new ( [ "--attributesToExclude" , "-eattrs" ] , ( ) => null )
86
+ Option < FileInfo [ ] ? > optionFilesWithAttributesToExclude = new ( name : "" , aliases : [ "--attributesToExclude" , "-eattrs" ] )
84
87
{
85
88
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." ,
86
89
Arity = ArgumentArity . ZeroOrMore ,
87
- IsRequired = false
90
+ Required = false ,
91
+ DefaultValueFactory = _ => null
88
92
} ;
89
93
90
- Option < FileInfo [ ] ? > optionFilesWithApisToExclude = new ( [ "--apisToExclude" , "-eapis" ] , ( ) => null )
94
+ Option < FileInfo [ ] ? > optionFilesWithApisToExclude = new ( name : "" , aliases : [ "--apisToExclude" , "-eapis" ] )
91
95
{
92
96
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." ,
93
97
Arity = ArgumentArity . ZeroOrMore ,
94
- IsRequired = false
98
+ Required = false ,
99
+ DefaultValueFactory = _ => null
95
100
} ;
96
101
97
- Option < bool > optionAddPartialModifier = new ( [ "--addPartialModifier" , "-apm" ] , ( ) => false )
102
+ Option < bool > optionAddPartialModifier = new ( name : "" , aliases : [ "--addPartialModifier" , "-apm" ] )
98
103
{
99
- Description = "Add the 'partial' modifier to types."
104
+ Description = "Add the 'partial' modifier to types." ,
105
+ DefaultValueFactory = _ => false
100
106
} ;
101
107
102
- Option < bool > optionAttachDebugger = new ( [ "--attachDebugger" , "-d" ] , ( ) => false )
108
+ Option < bool > optionAttachDebugger = new ( name : "" , aliases : [ "--attachDebugger" , "-d" ] )
103
109
{
104
- Description = "Stops the tool at startup, prints the process ID and waits for a debugger to attach."
110
+ Description = "Stops the tool at startup, prints the process ID and waits for a debugger to attach." ,
111
+ DefaultValueFactory = _ => false
105
112
} ;
106
113
107
114
// Custom ordering for the help menu.
108
- rootCommand . Add ( optionBeforeAssembliesFolderPath ) ;
109
- rootCommand . Add ( optionBeforeRefAssembliesFolderPath ) ;
110
- rootCommand . Add ( optionAfterAssembliesFolderPath ) ;
111
- rootCommand . Add ( optionAfterRefAssembliesFolderPath ) ;
112
- rootCommand . Add ( optionOutputFolderPath ) ;
113
- rootCommand . Add ( optionBeforeFriendlyName ) ;
114
- rootCommand . Add ( optionAfterFriendlyName ) ;
115
- rootCommand . Add ( optionTableOfContentsTitle ) ;
116
- rootCommand . Add ( optionFilesWithAssembliesToExclude ) ;
117
- rootCommand . Add ( optionFilesWithAttributesToExclude ) ;
118
- rootCommand . Add ( optionFilesWithApisToExclude ) ;
119
- rootCommand . Add ( optionAddPartialModifier ) ;
120
- rootCommand . Add ( optionAttachDebugger ) ;
121
-
122
- GenAPIDiffConfigurationBinder c = new ( optionBeforeAssembliesFolderPath ,
123
- optionBeforeRefAssembliesFolderPath ,
124
- optionAfterAssembliesFolderPath ,
125
- optionAfterRefAssembliesFolderPath ,
126
- optionOutputFolderPath ,
127
- optionBeforeFriendlyName ,
128
- optionAfterFriendlyName ,
129
- optionTableOfContentsTitle ,
130
- optionFilesWithAssembliesToExclude ,
131
- optionFilesWithAttributesToExclude ,
132
- optionFilesWithApisToExclude ,
133
- optionAddPartialModifier ,
134
- optionAttachDebugger ) ;
135
-
136
- rootCommand . SetHandler ( async ( DiffConfiguration diffConfig ) => await HandleCommandAsync ( diffConfig ) . ConfigureAwait ( false ) , c ) ;
137
- await rootCommand . InvokeAsync ( args ) ;
115
+ rootCommand . Options . Add ( optionBeforeAssembliesFolderPath ) ;
116
+ rootCommand . Options . Add ( optionBeforeRefAssembliesFolderPath ) ;
117
+ rootCommand . Options . Add ( optionAfterAssembliesFolderPath ) ;
118
+ rootCommand . Options . Add ( optionAfterRefAssembliesFolderPath ) ;
119
+ rootCommand . Options . Add ( optionOutputFolderPath ) ;
120
+ rootCommand . Options . Add ( optionBeforeFriendlyName ) ;
121
+ rootCommand . Options . Add ( optionAfterFriendlyName ) ;
122
+ rootCommand . Options . Add ( optionTableOfContentsTitle ) ;
123
+ rootCommand . Options . Add ( optionFilesWithAssembliesToExclude ) ;
124
+ rootCommand . Options . Add ( optionFilesWithAttributesToExclude ) ;
125
+ rootCommand . Options . Add ( optionFilesWithApisToExclude ) ;
126
+ rootCommand . Options . Add ( optionAddPartialModifier ) ;
127
+ rootCommand . Options . Add ( optionAttachDebugger ) ;
128
+
129
+ rootCommand . SetAction ( async ( ParseResult result ) =>
130
+ {
131
+ DiffConfiguration c = new (
132
+ BeforeAssembliesFolderPath : result . GetValue ( optionBeforeAssembliesFolderPath ) ?? throw new NullReferenceException ( "Null before assemblies directory" ) ,
133
+ BeforeAssemblyReferencesFolderPath : result . GetValue ( optionBeforeRefAssembliesFolderPath ) ,
134
+ AfterAssembliesFolderPath : result . GetValue ( optionAfterAssembliesFolderPath ) ?? throw new NullReferenceException ( "Null after assemblies directory" ) ,
135
+ AfterAssemblyReferencesFolderPath : result . GetValue ( optionAfterRefAssembliesFolderPath ) ,
136
+ OutputFolderPath : result . GetValue ( optionOutputFolderPath ) ?? throw new NullReferenceException ( "Null output directory" ) ,
137
+ BeforeFriendlyName : result . GetValue ( optionBeforeFriendlyName ) ?? throw new NullReferenceException ( "Null before friendly name" ) ,
138
+ AfterFriendlyName : result . GetValue ( optionAfterFriendlyName ) ?? throw new NullReferenceException ( "Null after friendly name" ) ,
139
+ TableOfContentsTitle : result . GetValue ( optionTableOfContentsTitle ) ?? throw new NullReferenceException ( "Null table of contents title" ) ,
140
+ FilesWithAssembliesToExclude : result . GetValue ( optionFilesWithAssembliesToExclude ) ,
141
+ FilesWithAttributesToExclude : result . GetValue ( optionFilesWithAttributesToExclude ) ,
142
+ FilesWithApisToExclude : result . GetValue ( optionFilesWithApisToExclude ) ,
143
+ AddPartialModifier : result . GetValue ( optionAddPartialModifier ) ,
144
+ AttachDebugger : result . GetValue ( optionAttachDebugger )
145
+ ) ;
146
+ await HandleCommandAsync ( c ) . ConfigureAwait ( false ) ;
147
+ } ) ;
148
+ await rootCommand . Parse ( args ) . InvokeAsync ( ) ;
138
149
}
139
150
140
151
private static Task HandleCommandAsync ( DiffConfiguration diffConfig )
0 commit comments