33using System . CommandLine ;
44using System . CommandLine . Binding ;
55using System . Text . Json ;
6+ using System . Text . Json . Serialization ;
67
78namespace ACE ;
89
@@ -148,34 +149,42 @@ protected override EstimateOptions GetBoundValue(BindingContext bindingContext)
148149
149150 private void ValidateProperUse ( BindingContext bindingContext )
150151 {
151- if ( bindingContext . ParseResult . GetValueForOption ( configurationFile ) != null &&
152- ( bindingContext . ParseResult . GetValueForOption ( mode ) != null ||
153- bindingContext . ParseResult . GetValueForOption ( threshold ) != null ||
154- bindingContext . ParseResult . GetValueForOption ( parameters ) != null ||
155- bindingContext . ParseResult . GetValueForOption ( currency ) != null ||
156- bindingContext . ParseResult . GetValueForOption ( generateJsonOutput ) != null ||
157- bindingContext . ParseResult . GetValueForOption ( shouldBeSilent ) != null ||
158- bindingContext . ParseResult . GetValueForOption ( stdout ) != null ||
159- bindingContext . ParseResult . GetValueForOption ( disableDetails ) != null ||
160- bindingContext . ParseResult . GetValueForOption ( jsonOutputFilename ) != null ||
161- bindingContext . ParseResult . GetValueForOption ( generateHtmlOutput ) != null ||
162- bindingContext . ParseResult . GetValueForOption ( dryRunOnly ) != null ||
163- bindingContext . ParseResult . GetValueForOption ( htmlOutputFilename ) != null ||
164- bindingContext . ParseResult . GetValueForOption ( outputFormat ) != null ||
165- bindingContext . ParseResult . GetValueForOption ( disableCache ) != null ||
166- bindingContext . ParseResult . GetValueForOption ( terraformExecutable ) != null ||
167- bindingContext . ParseResult . GetValueForOption ( conversionRate ) != null ||
168- bindingContext . ParseResult . GetValueForOption ( cacheHandler ) != null ||
169- bindingContext . ParseResult . GetValueForOption ( cacheStorageAccountName ) != null ||
170- bindingContext . ParseResult . GetValueForOption ( webhookUrl ) != null ||
171- bindingContext . ParseResult . GetValueForOption ( logFile ) != null ||
172- bindingContext . ParseResult . GetValueForOption ( optOutCheckingNewVersion ) != null ||
173- bindingContext . ParseResult . GetValueForOption ( mockedRetailAPIResponsePaths ) != null ||
174- bindingContext . ParseResult . GetValueForOption ( userGeneratedWhatIf ) != null ||
175- bindingContext . ParseResult . GetValueForOption ( generateMarkdownOutput ) != null ||
176- bindingContext . ParseResult . GetValueForOption ( markdownOutputFilename ) != null ) )
152+ var options = new Dictionary < string , object ? >
177153 {
178- throw new Exception ( "Cannot use both --configuration-file and other options besides --webhook-authorization and --inline." ) ;
179- }
154+ { mode . Name , bindingContext . ParseResult . GetValueForOption ( mode ) } ,
155+ { threshold . Name , bindingContext . ParseResult . GetValueForOption ( threshold ) } ,
156+ { parameters . Name , bindingContext . ParseResult . GetValueForOption ( parameters ) } ,
157+ { currency . Name , bindingContext . ParseResult . GetValueForOption ( currency ) } ,
158+ { generateJsonOutput . Name , bindingContext . ParseResult . GetValueForOption ( generateJsonOutput ) } ,
159+ { shouldBeSilent . Name , bindingContext . ParseResult . GetValueForOption ( shouldBeSilent ) } ,
160+ { stdout . Name , bindingContext . ParseResult . GetValueForOption ( stdout ) } ,
161+ { disableDetails . Name , bindingContext . ParseResult . GetValueForOption ( disableDetails ) } ,
162+ { jsonOutputFilename . Name , bindingContext . ParseResult . GetValueForOption ( jsonOutputFilename ) } ,
163+ { generateHtmlOutput . Name , bindingContext . ParseResult . GetValueForOption ( generateHtmlOutput ) } ,
164+ { outputFormat . Name , bindingContext . ParseResult . GetValueForOption ( outputFormat ) } ,
165+ { disableCache . Name , bindingContext . ParseResult . GetValueForOption ( disableCache ) } ,
166+ { terraformExecutable . Name , bindingContext . ParseResult . GetValueForOption ( terraformExecutable ) } ,
167+ { conversionRate . Name , bindingContext . ParseResult . GetValueForOption ( conversionRate ) } ,
168+ { cacheHandler . Name , bindingContext . ParseResult . GetValueForOption ( cacheHandler ) } ,
169+ { cacheStorageAccountName . Name , bindingContext . ParseResult . GetValueForOption ( cacheStorageAccountName ) } ,
170+ { webhookUrl . Name , bindingContext . ParseResult . GetValueForOption ( webhookUrl ) } ,
171+ { logFile . Name , bindingContext . ParseResult . GetValueForOption ( logFile ) } ,
172+ { optOutCheckingNewVersion . Name , bindingContext . ParseResult . GetValueForOption ( optOutCheckingNewVersion ) } ,
173+ { mockedRetailAPIResponsePaths . Name , bindingContext . ParseResult . GetValueForOption ( mockedRetailAPIResponsePaths ) } ,
174+ { userGeneratedWhatIf . Name , bindingContext . ParseResult . GetValueForOption ( userGeneratedWhatIf ) } ,
175+ { generateMarkdownOutput . Name , bindingContext . ParseResult . GetValueForOption ( generateMarkdownOutput ) } ,
176+ { markdownOutputFilename . Name , bindingContext . ParseResult . GetValueForOption ( markdownOutputFilename ) } ,
177+ } ;
178+
179+ if ( bindingContext . ParseResult . GetValueForOption ( configurationFile ) == null ) return ;
180+
181+ var optionsWithNonNullValue = options . Where ( o => o . Value != null ) . ToArray ( ) ;
182+ if ( optionsWithNonNullValue . Length == 0 ) return ;
183+
184+ var parsedNonNullableOptions = string . Join ( ", " , optionsWithNonNullValue . Select ( o => $ "[{ o . Key } ]:[{ o . Value } ]") ) ;
185+
186+ throw new Exception (
187+ $ "Cannot use both --configuration-file and other options besides --webhook-authorization and --inline. Those options are: { parsedNonNullableOptions } ") ;
188+
180189 }
181190}
0 commit comments