@@ -159,7 +159,7 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
159159 var fwVersion = string . IsNullOrEmpty ( _fwVersion ) ? "latest" : _fwVersion ;
160160
161161 // compose query
162- string requestUri = $ "{ repoName } /?query=name:{ _targetName } version:^{ fwVersion } $";
162+ string requestUri = $ "{ repoName } /?query=name:^ { _targetName } $ version:^{ fwVersion } $";
163163
164164 string downloadUrl = string . Empty ;
165165
@@ -233,6 +233,7 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
233233 string responseBody = await response . Content . ReadAsStringAsync ( ) ;
234234
235235 bool targetNotFound = false ;
236+
236237 bool packageOutdated = false ;
237238 List < CloudsmithPackageInfo > packageInfo = null ;
238239
@@ -246,39 +247,69 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
246247 // parse response
247248 packageInfo = JsonConvert . DeserializeObject < List < CloudsmithPackageInfo > > ( responseBody ) ;
248249
249- // if no specific version was requested, use latest available
250- if ( string . IsNullOrEmpty ( _fwVersion ) )
250+ // sanity check
251+ if ( packageInfo . Count ( ) != 1 )
251252 {
252- _fwVersion = packageInfo . ElementAt ( 0 ) . Version ;
253- // grab download URL
254- downloadUrl = packageInfo . ElementAt ( 0 ) . DownloadUrl ;
253+ Console . WriteLine ( "" ) ;
254+
255+ if ( Verbosity >= VerbosityLevel . Normal )
256+ {
257+ Console . ForegroundColor = ConsoleColor . Red ;
258+
259+ Console . WriteLine ( $ "Several hits returned, expecting only one!") ;
260+ Console . Write ( "Please report this issue." ) ;
261+
262+ return ExitCodes . E9005 ;
263+ }
255264 }
256265 else
257266 {
258- //get the download Url from the Cloudsmith Package info
259- // addition check if the cloudsmith json return empty json
260- if ( packageInfo is null || packageInfo . Count == 0 )
267+ // if no specific version was requested, use latest available
268+ if ( string . IsNullOrEmpty ( _fwVersion ) )
261269 {
262- return ExitCodes . E9005 ;
270+ _fwVersion = packageInfo . ElementAt ( 0 ) . Version ;
271+ // grab download URL
272+ downloadUrl = packageInfo . ElementAt ( 0 ) . DownloadUrl ;
263273 }
264274 else
265275 {
266- downloadUrl = packageInfo . Where ( w => w . Version == _fwVersion ) . Select ( s => s . DownloadUrl ) . FirstOrDefault ( ) ;
276+ //get the download Url from the Cloudsmith Package info
277+ // addition check if the cloudsmith json return empty json
278+ if ( packageInfo is null || packageInfo . Count == 0 )
279+ {
280+ return ExitCodes . E9005 ;
281+ }
282+ else
283+ {
284+ downloadUrl = packageInfo . Where ( w => w . Version == _fwVersion ) . Select ( s => s . DownloadUrl ) . FirstOrDefault ( ) ;
285+ }
267286 }
268- }
269287
270- // sanity check for target name matching requested
271- if ( packageInfo . ElementAt ( 0 ) . TargetName != _targetName )
272- {
273- targetNotFound = true ;
274- }
275- else
276- {
277- // check package published date
278- if ( packageInfo . ElementAt ( 0 ) . PackageDate < DateTime . UtcNow . AddMonths ( - 2 ) )
288+ // sanity check for target name matching requested
289+ if ( packageInfo . ElementAt ( 0 ) . TargetName != _targetName )
290+ {
291+ targetNotFound = true ;
292+
293+ Console . WriteLine ( "" ) ;
294+
295+ if ( Verbosity >= VerbosityLevel . Normal )
296+ {
297+ Console . ForegroundColor = ConsoleColor . Red ;
298+
299+ Console . WriteLine ( $ "There's a mismatch in the target name. Requested '{ _targetName } ' but got '{ packageInfo . ElementAt ( 0 ) . TargetName } '!") ;
300+ Console . Write ( "Please report this issue." ) ;
301+
302+ return ExitCodes . E9005 ;
303+ }
304+ }
305+ else
279306 {
280- // if older than 2 months warn user
281- packageOutdated = true ;
307+ // check package published date
308+ if ( packageInfo . ElementAt ( 0 ) . PackageDate < DateTime . UtcNow . AddMonths ( - 2 ) )
309+ {
310+ // if older than 2 months warn user
311+ packageOutdated = true ;
312+ }
282313 }
283314 }
284315 }
0 commit comments