2
2
// Licensed under the MIT license.
3
3
4
4
using System . CommandLine ;
5
- using System . CommandLine . Invocation ;
6
5
using System . IO ;
7
6
using System . Threading . Tasks ;
8
7
using Microsoft . Extensions . Logging ;
@@ -15,62 +14,62 @@ static async Task<int> Main(string[] args)
15
14
{
16
15
var rootCommand = new RootCommand ( ) {
17
16
} ;
18
-
17
+
19
18
// command option parameters and aliases
20
- var descriptionOption = new Option ( "--openapi" , "Input OpenAPI description file path or URL" , typeof ( string ) ) ;
19
+ var descriptionOption = new Option < string > ( "--openapi" , "Input OpenAPI description file path or URL" ) ;
21
20
descriptionOption . AddAlias ( "-d" ) ;
22
21
23
- var outputOption = new Option ( "--output" , " The output directory path for the generated file.", typeof ( FileInfo ) , ( ) => "./output" , arity : ArgumentArity . ZeroOrOne ) ;
22
+ var outputOption = new Option < FileInfo > ( "--output" , ( ) => new FileInfo ( "./output" ) , " The output directory path for the generated file.") { Arity = ArgumentArity . ZeroOrOne } ;
24
23
outputOption . AddAlias ( "-o" ) ;
25
24
26
- var versionOption = new Option ( "--version" , "OpenAPI specification version" , typeof ( OpenApiSpecVersion ) ) ;
25
+ var versionOption = new Option < OpenApiSpecVersion ? > ( "--version" , "OpenAPI specification version" ) ;
27
26
versionOption . AddAlias ( "-v" ) ;
28
27
29
- var formatOption = new Option ( "--format" , "File format" , typeof ( OpenApiFormat ) ) ;
28
+ var formatOption = new Option < OpenApiFormat ? > ( "--format" , "File format" ) ;
30
29
formatOption . AddAlias ( "-f" ) ;
31
30
32
- var logLevelOption = new Option ( "--loglevel" , "The log level to use when logging messages to the main output." , typeof ( LogLevel ) , ( ) => LogLevel . Warning ) ;
31
+ var logLevelOption = new Option < LogLevel > ( "--loglevel" , ( ) => LogLevel . Warning , "The log level to use when logging messages to the main output." ) ;
33
32
logLevelOption . AddAlias ( "-ll" ) ;
34
33
35
- var inlineOption = new Option ( "--inline" , "Inline $ref instances" , typeof ( bool ) ) ;
36
- inlineOption . AddAlias ( "-i" ) ;
37
-
38
- var resolveExternalOption = new Option ( "--resolve-external" , "Resolve external $refs" , typeof ( bool ) ) ;
39
- resolveExternalOption . AddAlias ( "-ex" ) ;
40
-
41
- var filterByOperationIdsOption = new Option ( "--filter-by-operationids" , "Filters OpenApiDocument by OperationId(s) provided" , typeof ( string ) ) ;
34
+ var filterByOperationIdsOption = new Option < string > ( "--filter-by-operationids" , "Filters OpenApiDocument by OperationId(s) provided" ) ;
42
35
filterByOperationIdsOption . AddAlias ( "-op" ) ;
43
36
44
- var filterByTagsOption = new Option ( "--filter-by-tags" , "Filters OpenApiDocument by Tag(s) provided" , typeof ( string ) ) ;
37
+ var filterByTagsOption = new Option < string > ( "--filter-by-tags" , "Filters OpenApiDocument by Tag(s) provided" ) ;
45
38
filterByTagsOption . AddAlias ( "-t" ) ;
46
39
47
- var filterByCollectionOption = new Option ( "--filter-by-collection" , "Filters OpenApiDocument by Postman collection provided" , typeof ( string ) ) ;
40
+ var filterByCollectionOption = new Option < string > ( "--filter-by-collection" , "Filters OpenApiDocument by Postman collection provided" ) ;
48
41
filterByCollectionOption . AddAlias ( "-c" ) ;
49
42
43
+ var inlineOption = new Option < bool > ( "--inline" , "Inline $ref instances" ) ;
44
+ inlineOption . AddAlias ( "-i" ) ;
45
+
46
+ var resolveExternalOption = new Option < bool > ( "--resolve-external" , "Resolve external $refs" ) ;
47
+ resolveExternalOption . AddAlias ( "-ex" ) ;
48
+
50
49
var validateCommand = new Command ( "validate" )
51
50
{
52
51
descriptionOption ,
53
52
logLevelOption
54
53
} ;
55
54
56
- validateCommand . Handler = CommandHandler . Create < string , LogLevel > ( OpenApiService . ValidateOpenApiDocument ) ;
55
+ validateCommand . SetHandler < string , LogLevel > ( OpenApiService . ValidateOpenApiDocument , descriptionOption , logLevelOption ) ;
57
56
58
57
var transformCommand = new Command ( "transform" )
59
58
{
60
59
descriptionOption ,
61
60
outputOption ,
62
61
versionOption ,
63
62
formatOption ,
64
- logLevelOption ,
65
- inlineOption ,
66
- resolveExternalOption ,
63
+ logLevelOption ,
67
64
filterByOperationIdsOption ,
68
65
filterByTagsOption ,
69
- filterByCollectionOption
66
+ filterByCollectionOption ,
67
+ inlineOption ,
68
+ resolveExternalOption ,
70
69
} ;
71
70
72
- transformCommand . Handler = CommandHandler . Create < string , FileInfo , OpenApiSpecVersion ? , OpenApiFormat ? , LogLevel , string , string , string , bool , bool > (
73
- OpenApiService . ProcessOpenApiDocument ) ;
71
+ transformCommand . SetHandler < string , FileInfo , OpenApiSpecVersion ? , OpenApiFormat ? , LogLevel , bool , bool , string , string , string > (
72
+ OpenApiService . ProcessOpenApiDocument , descriptionOption , outputOption , versionOption , formatOption , logLevelOption , inlineOption , resolveExternalOption , filterByOperationIdsOption , filterByTagsOption , filterByCollectionOption ) ;
74
73
75
74
rootCommand . Add ( transformCommand ) ;
76
75
rootCommand . Add ( validateCommand ) ;
0 commit comments