1- using System . CommandLine ;
1+ using System . CommandLine ;
22using System . CommandLine . Invocation ;
33using System . Text . Json ;
44using TypescriptClientGenerator . Generators ;
1616 DefaultValueFactory = _ => new FileInfo ( "generated.ts" )
1717} ;
1818
19+ var clientNameOption = new Option < string ? > ( "--client-name" , "-c" )
20+ {
21+ Description = "The name of the generated client class (default: derived from OpenAPI title)"
22+ } ;
23+
1924var rootCommand = new RootCommand ( "Generates a TypeScript client from an OpenAPI specification" )
2025{
2126 inputOption ,
22- outputOption
27+ outputOption ,
28+ clientNameOption
2329} ;
2430
25- rootCommand . Action = new GenerateAction ( inputOption , outputOption ) ;
31+ rootCommand . Action = new GenerateAction ( inputOption , outputOption , clientNameOption ) ;
2632
2733return await rootCommand . Parse ( args ) . InvokeAsync ( ) ;
2834
2935class GenerateAction : AsynchronousCommandLineAction
3036{
3137 private readonly Option < FileInfo > _inputOption ;
3238 private readonly Option < FileInfo > _outputOption ;
39+ private readonly Option < string ? > _clientNameOption ;
3340
34- public GenerateAction ( Option < FileInfo > inputOption , Option < FileInfo > outputOption )
41+ public GenerateAction ( Option < FileInfo > inputOption , Option < FileInfo > outputOption , Option < string ? > clientNameOption )
3542 {
3643 _inputOption = inputOption ;
3744 _outputOption = outputOption ;
45+ _clientNameOption = clientNameOption ;
3846 }
3947
4048 public override async Task < int > InvokeAsync ( ParseResult parseResult , CancellationToken cancellationToken = default )
4149 {
4250 var inputFile = parseResult . GetValue ( _inputOption ) ! ;
4351 var outputFile = parseResult . GetValue ( _outputOption ) ! ;
52+ var clientName = parseResult . GetValue ( _clientNameOption ) ;
4453
4554 if ( ! inputFile . Exists )
4655 {
@@ -66,7 +75,7 @@ public override async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
6675 return 1 ;
6776 }
6877
69- var generator = new TypeScriptGenerator ( openApi ) ;
78+ var generator = new TypeScriptGenerator ( openApi , clientName ) ;
7079 var generatedCode = generator . Generate ( ) ;
7180
7281 await File . WriteAllTextAsync ( outputFile . FullName , generatedCode , cancellationToken ) ;
0 commit comments