@@ -172,99 +172,113 @@ protected override void ProcessRecord()
172172
173173 private void ProcessResourceNameParameterSet ( )
174174 {
175- WriteDebug ( "In FindPSResource::ProcessResourceNameParameterSet()" ) ;
176- // only cases where Name is allowed to not be specified is if Type or Tag parameters are
177- if ( ! MyInvocation . BoundParameters . ContainsKey ( nameof ( Name ) ) )
175+ try
178176 {
179- if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Tag ) ) )
177+ WriteDebug ( "In FindPSResource::ProcessResourceNameParameterSet()" ) ;
178+ // only cases where Name is allowed to not be specified is if Type or Tag parameters are
179+ if ( ! MyInvocation . BoundParameters . ContainsKey ( nameof ( Name ) ) )
180180 {
181- ProcessTags ( ) ;
182- return ;
183- }
184- else if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Type ) ) )
185- {
186- Name = new string [ ] { "*" } ;
181+ WriteDebug ( "Name parameter not provided, checking for Type or Tag parameters" ) ;
182+ if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Tag ) ) )
183+ {
184+ ProcessTags ( ) ;
185+ return ;
186+ }
187+ else if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Type ) ) )
188+ {
189+ Name = new string [ ] { "*" } ;
190+ }
191+ else
192+ {
193+ ThrowTerminatingError ( new ErrorRecord (
194+ new PSInvalidOperationException ( "Name parameter must be provided, unless Tag or Type parameters are used." ) ,
195+ "NameParameterNotProvided" ,
196+ ErrorCategory . InvalidOperation ,
197+ this ) ) ;
198+ }
187199 }
188- else
200+
201+ WriteVerbose ( "Processing Name parameter for Find-PSResource cmdlet" ) ;
202+ WriteDebug ( "Filtering package name(s) on wildcards" ) ;
203+ Name = Utils . ProcessNameWildcards ( Name , removeWildcardEntries : false , out string [ ] errorMsgs , out bool nameContainsWildcard ) ;
204+ WriteVerbose ( $ "Name parameter processed, contains { Name . Length } entries") ;
205+
206+ foreach ( string error in errorMsgs )
189207 {
190- ThrowTerminatingError ( new ErrorRecord (
191- new PSInvalidOperationException ( "Name parameter must be provided, unless Tag or Type parameters are used." ) ,
192- "NameParameterNotProvided " ,
193- ErrorCategory . InvalidOperation ,
208+ WriteError ( new ErrorRecord (
209+ new PSInvalidOperationException ( error ) ,
210+ "ErrorFilteringNamesForUnsupportedWildcards " ,
211+ ErrorCategory . InvalidArgument ,
194212 this ) ) ;
195213 }
196- }
197-
198- WriteDebug ( "Filtering package name(s) on wildcards" ) ;
199- Name = Utils . ProcessNameWildcards ( Name , removeWildcardEntries : false , out string [ ] errorMsgs , out bool nameContainsWildcard ) ;
200-
201- foreach ( string error in errorMsgs )
202- {
203- WriteError ( new ErrorRecord (
204- new PSInvalidOperationException ( error ) ,
205- "ErrorFilteringNamesForUnsupportedWildcards" ,
206- ErrorCategory . InvalidArgument ,
207- this ) ) ;
208- }
209214
210- // this catches the case where Name wasn't passed in as null or empty,
211- // but after filtering out unsupported wildcard names there are no elements left in namesToSearch
212- if ( Name . Length == 0 )
213- {
214- WriteDebug ( "Package name(s) could not be resolved" ) ;
215- return ;
216- }
215+ // this catches the case where Name wasn't passed in as null or empty,
216+ // but after filtering out unsupported wildcard names there are no elements left in namesToSearch
217+ if ( Name . Length == 0 )
218+ {
219+ WriteDebug ( "Package name(s) could not be resolved" ) ;
220+ return ;
221+ }
217222
218- // determine/parse out Version param
219- VersionType versionType = VersionType . VersionRange ;
220- NuGetVersion nugetVersion = null ;
221- VersionRange versionRange = null ;
223+ // determine/parse out Version param
224+ VersionType versionType = VersionType . VersionRange ;
225+ NuGetVersion nugetVersion = null ;
226+ VersionRange versionRange = null ;
222227
223- if ( Version != null )
224- {
225- WriteDebug ( "Parsing package version" ) ;
226- if ( ! NuGetVersion . TryParse ( Version , out nugetVersion ) )
228+ if ( Version != null )
227229 {
228- if ( Version . Trim ( ) . Equals ( "*" ) )
230+ WriteDebug ( "Parsing package version" ) ;
231+ if ( ! NuGetVersion . TryParse ( Version , out nugetVersion ) )
229232 {
230- versionRange = VersionRange . All ;
231- versionType = VersionType . VersionRange ;
233+ if ( Version . Trim ( ) . Equals ( "*" ) )
234+ {
235+ versionRange = VersionRange . All ;
236+ versionType = VersionType . VersionRange ;
237+ }
238+ else if ( ! VersionRange . TryParse ( Version , out versionRange ) )
239+ {
240+ WriteError ( new ErrorRecord (
241+ new ArgumentException ( "Argument for -Version parameter is not in the proper format" ) ,
242+ "IncorrectVersionFormat" ,
243+ ErrorCategory . InvalidArgument ,
244+ this ) ) ;
245+
246+ return ;
247+ }
232248 }
233- else if ( ! VersionRange . TryParse ( Version , out versionRange ) )
249+ else
234250 {
235- WriteError ( new ErrorRecord (
236- new ArgumentException ( "Argument for -Version parameter is not in the proper format" ) ,
237- "IncorrectVersionFormat" ,
238- ErrorCategory . InvalidArgument ,
239- this ) ) ;
240-
241- return ;
251+ versionType = VersionType . SpecificVersion ;
242252 }
243253 }
244254 else
245255 {
246- versionType = VersionType . SpecificVersion ;
256+ versionType = VersionType . NoVersion ;
247257 }
248- }
249- else
250- {
251- versionType = VersionType . NoVersion ;
252- }
253258
254- foreach ( PSResourceInfo pkg in _findHelper . FindByResourceName (
255- name : Name ,
256- type : Type ,
257- versionRange : versionRange ,
258- nugetVersion : nugetVersion ,
259- versionType : versionType ,
260- version : Version ,
261- prerelease : Prerelease ,
262- tag : Tag ,
263- repository : Repository ,
264- includeDependencies : IncludeDependencies ,
265- suppressErrors : false ) )
259+ foreach ( PSResourceInfo pkg in _findHelper . FindByResourceName (
260+ name : Name ,
261+ type : Type ,
262+ versionRange : versionRange ,
263+ nugetVersion : nugetVersion ,
264+ versionType : versionType ,
265+ version : Version ,
266+ prerelease : Prerelease ,
267+ tag : Tag ,
268+ repository : Repository ,
269+ includeDependencies : IncludeDependencies ,
270+ suppressErrors : false ) )
271+ {
272+ WriteObject ( pkg ) ;
273+ }
274+ }
275+ catch ( Exception ex )
266276 {
267- WriteObject ( pkg ) ;
277+ WriteError ( new ErrorRecord (
278+ ex ,
279+ "FindPSResourceError" ,
280+ ErrorCategory . NotSpecified ,
281+ this ) ) ;
268282 }
269283 }
270284
0 commit comments