@@ -219,46 +219,68 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
219219
220220 string responseBody = await response . Content . ReadAsStringAsync ( ) ;
221221
222+ bool targetNotFound = false ;
223+
222224 // check for empty array
223225 if ( responseBody == "[]" )
224226 {
225- if ( Verbosity >= VerbosityLevel . Normal )
227+ targetNotFound = true ;
228+ }
229+ else
230+ {
231+ // parse response
232+ List < CloudsmithPackageInfo > packageInfo = JsonConvert . DeserializeObject < List < CloudsmithPackageInfo > > ( responseBody ) ;
233+
234+ // if no specific version was requested, use latest available
235+ if ( string . IsNullOrEmpty ( _fwVersion ) )
226236 {
227- Console . ForegroundColor = ConsoleColor . White ;
228- Console . WriteLine ( "" ) ;
229- Console . Write ( $ "Trying to find { _targetName } in community targets repository...") ;
237+ _fwVersion = packageInfo . ElementAt ( 0 ) . Version ;
238+ // grab download URL
239+ downloadUrl = packageInfo . ElementAt ( 0 ) . DownloadUrl ;
240+ }
241+ else
242+ {
243+ //get the download Url from the Cloudsmith Package info
244+ // addition check if the cloudsmith json return empty json
245+ if ( packageInfo is null || packageInfo . Count == 0 )
246+ {
247+ return ExitCodes . E9005 ;
248+ }
249+ else
250+ {
251+ downloadUrl = packageInfo . Where ( w => w . Version == _fwVersion ) . Select ( s => s . DownloadUrl ) . FirstOrDefault ( ) ;
252+ }
230253 }
231254
232- // try with community targets
233-
234- requestUri = $ "{ _cloudsmithPackages } /{ _communityTargetsRepo } /?page=1&query=^{ _targetName } $ { fwVersion } ";
255+ // sanity check for target name matching requested
256+ if ( packageInfo . ElementAt ( 0 ) . TargetName != _targetName )
257+ {
258+ targetNotFound = true ;
259+ }
260+ }
235261
236- response = await _cloudsmithClient . GetAsync ( requestUri ) ;
262+ if ( targetNotFound )
263+ {
264+ // can't find this target
237265
238- responseBody = await response . Content . ReadAsStringAsync ( ) ;
266+ Console . WriteLine ( "" ) ;
239267
240- if ( responseBody == "[]" )
268+ if ( Verbosity >= VerbosityLevel . Normal )
241269 {
242- // can't find this target
270+ // output helpful message
271+ Console . ForegroundColor = ConsoleColor . Red ;
243272
273+ Console . WriteLine ( "" ) ;
274+ Console . WriteLine ( "*************************** ERROR **************************" ) ;
275+ Console . WriteLine ( "Couldn't find this target in our Cloudsmith repositories!" ) ;
276+ Console . WriteLine ( "To list the available targets use this option --listtargets." ) ;
277+ Console . WriteLine ( "************************************************************" ) ;
244278 Console . WriteLine ( "" ) ;
245279
246- if ( Verbosity >= VerbosityLevel . Normal )
247- {
248- // output helpful message
249- Console . ForegroundColor = ConsoleColor . Yellow ;
250-
251- Console . WriteLine ( "" ) ;
252- Console . WriteLine ( "*************************** ERROR **************************" ) ;
253- Console . WriteLine ( "Couldn't find this target in our Cloudsmith repositories!" ) ;
254- Console . WriteLine ( "To list the available targets use this option --listtargets." ) ;
255- Console . WriteLine ( "************************************************************" ) ;
256- Console . WriteLine ( "" ) ;
257-
258- Console . ForegroundColor = ConsoleColor . White ;
259- }
260- return ExitCodes . E9005 ;
280+ Console . ForegroundColor = ConsoleColor . White ;
261281 }
282+
283+ return ExitCodes . E9005 ;
262284 }
263285
264286 if ( Verbosity >= VerbosityLevel . Normal )
@@ -268,30 +290,6 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
268290 Console . ForegroundColor = ConsoleColor . White ;
269291 }
270292
271- // parse response
272- List < CloudsmithPackageInfo > packageInfo = JsonConvert . DeserializeObject < List < CloudsmithPackageInfo > > ( responseBody ) ;
273-
274- // if no specific version was requested, use latest available
275- if ( string . IsNullOrEmpty ( _fwVersion ) )
276- {
277- _fwVersion = packageInfo . ElementAt ( 0 ) . Version ;
278- // grab download URL
279- downloadUrl = packageInfo . ElementAt ( 0 ) . DownloadUrl ;
280- }
281- else
282- {
283- //get the download Url from the Cloudsmith Package info
284- // addition check if the cloudsmith json return empty json
285- if ( packageInfo is null || packageInfo . Count == 0 )
286- {
287- return ExitCodes . E9005 ;
288- }
289- else
290- {
291- downloadUrl = packageInfo . Where ( w => w . Version == _fwVersion ) . Select ( s => s . DownloadUrl ) . FirstOrDefault ( ) ;
292- }
293- }
294-
295293 // set exposed property
296294 Version = _fwVersion ;
297295
0 commit comments