@@ -115,20 +115,15 @@ public sealed class FindPSResource : PSCmdlet
115115
116116 protected override void BeginProcessing ( )
117117 {
118- WriteVerbose ( "Beginning Find-PSResource processing" ) ;
119118 _cancellationTokenSource = new CancellationTokenSource ( ) ;
120119
121120 var networkCred = Credential != null ? new NetworkCredential ( Credential . UserName , Credential . Password ) : null ;
122121
123- WriteVerbose ( "Creating FindHelper instance" ) ;
124-
125122 _findHelper = new FindHelper (
126123 cancellationToken : _cancellationTokenSource . Token ,
127124 cmdletPassedIn : this ,
128125 networkCredential : networkCred ) ;
129126
130- WriteVerbose ( "FindHelper instance created successfully" ) ;
131-
132127 // Create a repository story (the PSResourceRepository.xml file) if it does not already exist
133128 // This is to create a better experience for those who have just installed v3 and want to get up and running quickly
134129 RepositorySettings . CheckRepositoryStore ( ) ;
@@ -172,120 +167,98 @@ protected override void ProcessRecord()
172167
173168 private void ProcessResourceNameParameterSet ( )
174169 {
175- try
170+ // only cases where Name is allowed to not be specified is if Type or Tag parameters are
171+ if ( ! MyInvocation . BoundParameters . ContainsKey ( nameof ( Name ) ) )
176172 {
177- WriteDebug ( "Testing" ) ;
178- WriteDebug ( "In FindPSResource::ProcessResourceNameParameterSet() XXXXXXXXXXX" ) ;
179- WriteVerbose ( "checking if Name parameter is specified" ) ;
180-
181- var check = MyInvocation ? . BoundParameters ? . ContainsKey ( nameof ( Name ) ) ;
182-
183- WriteVerbose ( "Value of check for Name parameter: " + check ) ;
184-
185- // only cases where Name is allowed to not be specified is if Type or Tag parameters are
186- if ( ! MyInvocation . BoundParameters . ContainsKey ( nameof ( Name ) ) )
173+ if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Tag ) ) )
187174 {
188- WriteDebug ( "Name parameter not provided, checking for Type or Tag parameters" ) ;
189- if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Tag ) ) )
190- {
191- ProcessTags ( ) ;
192- return ;
193- }
194- else if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Type ) ) )
195- {
196- Name = new string [ ] { "*" } ;
197- }
198- else
199- {
200- ThrowTerminatingError ( new ErrorRecord (
201- new PSInvalidOperationException ( "Name parameter must be provided, unless Tag or Type parameters are used." ) ,
202- "NameParameterNotProvided" ,
203- ErrorCategory . InvalidOperation ,
204- this ) ) ;
205- }
175+ ProcessTags ( ) ;
176+ return ;
206177 }
207-
208- WriteVerbose ( "Processing Name parameter for Find-PSResource cmdlet" ) ;
209- WriteDebug ( "Filtering package name(s) on wildcards" ) ;
210- Name = Utils . ProcessNameWildcards ( Name , removeWildcardEntries : false , out string [ ] errorMsgs , out bool nameContainsWildcard ) ;
211- WriteVerbose ( $ "Name parameter processed, contains { Name . Length } entries") ;
212-
213- foreach ( string error in errorMsgs )
178+ else if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Type ) ) )
214179 {
215- WriteError ( new ErrorRecord (
216- new PSInvalidOperationException ( error ) ,
217- "ErrorFilteringNamesForUnsupportedWildcards" ,
218- ErrorCategory . InvalidArgument ,
219- this ) ) ;
180+ Name = new string [ ] { "*" } ;
220181 }
221-
222- // this catches the case where Name wasn't passed in as null or empty,
223- // but after filtering out unsupported wildcard names there are no elements left in namesToSearch
224- if ( Name . Length == 0 )
182+ else
225183 {
226- WriteDebug ( "Package name(s) could not be resolved" ) ;
227- return ;
184+ ThrowTerminatingError ( new ErrorRecord (
185+ new PSInvalidOperationException ( "Name parameter must be provided, unless Tag or Type parameters are used." ) ,
186+ "NameParameterNotProvided" ,
187+ ErrorCategory . InvalidOperation ,
188+ this ) ) ;
228189 }
190+ }
229191
230- // determine/parse out Version param
231- VersionType versionType = VersionType . VersionRange ;
232- NuGetVersion nugetVersion = null ;
233- VersionRange versionRange = null ;
192+ WriteDebug ( "Filtering package name(s) on wildcards" ) ;
193+ Name = Utils . ProcessNameWildcards ( Name , removeWildcardEntries : false , out string [ ] errorMsgs , out bool nameContainsWildcard ) ;
234194
235- if ( Version != null )
195+ foreach ( string error in errorMsgs )
196+ {
197+ WriteError ( new ErrorRecord (
198+ new PSInvalidOperationException ( error ) ,
199+ "ErrorFilteringNamesForUnsupportedWildcards" ,
200+ ErrorCategory . InvalidArgument ,
201+ this ) ) ;
202+ }
203+
204+ // this catches the case where Name wasn't passed in as null or empty,
205+ // but after filtering out unsupported wildcard names there are no elements left in namesToSearch
206+ if ( Name . Length == 0 )
207+ {
208+ WriteDebug ( "Package name(s) could not be resolved" ) ;
209+ return ;
210+ }
211+
212+ // determine/parse out Version param
213+ VersionType versionType = VersionType . VersionRange ;
214+ NuGetVersion nugetVersion = null ;
215+ VersionRange versionRange = null ;
216+
217+ if ( Version != null )
218+ {
219+ WriteDebug ( "Parsing package version" ) ;
220+ if ( ! NuGetVersion . TryParse ( Version , out nugetVersion ) )
236221 {
237- WriteDebug ( "Parsing package version" ) ;
238- if ( ! NuGetVersion . TryParse ( Version , out nugetVersion ) )
222+ if ( Version . Trim ( ) . Equals ( "*" ) )
239223 {
240- if ( Version . Trim ( ) . Equals ( "*" ) )
241- {
242- versionRange = VersionRange . All ;
243- versionType = VersionType . VersionRange ;
244- }
245- else if ( ! VersionRange . TryParse ( Version , out versionRange ) )
246- {
247- WriteError ( new ErrorRecord (
248- new ArgumentException ( "Argument for -Version parameter is not in the proper format" ) ,
249- "IncorrectVersionFormat" ,
250- ErrorCategory . InvalidArgument ,
251- this ) ) ;
252-
253- return ;
254- }
224+ versionRange = VersionRange . All ;
225+ versionType = VersionType . VersionRange ;
255226 }
256- else
227+ else if ( ! VersionRange . TryParse ( Version , out versionRange ) )
257228 {
258- versionType = VersionType . SpecificVersion ;
229+ WriteError ( new ErrorRecord (
230+ new ArgumentException ( "Argument for -Version parameter is not in the proper format" ) ,
231+ "IncorrectVersionFormat" ,
232+ ErrorCategory . InvalidArgument ,
233+ this ) ) ;
234+
235+ return ;
259236 }
260237 }
261238 else
262239 {
263- versionType = VersionType . NoVersion ;
264- }
265-
266- foreach ( PSResourceInfo pkg in _findHelper . FindByResourceName (
267- name : Name ,
268- type : Type ,
269- versionRange : versionRange ,
270- nugetVersion : nugetVersion ,
271- versionType : versionType ,
272- version : Version ,
273- prerelease : Prerelease ,
274- tag : Tag ,
275- repository : Repository ,
276- includeDependencies : IncludeDependencies ,
277- suppressErrors : false ) )
278- {
279- WriteObject ( pkg ) ;
240+ versionType = VersionType . SpecificVersion ;
280241 }
281242 }
282- catch ( Exception ex )
243+ else
283244 {
284- WriteError ( new ErrorRecord (
285- ex ,
286- "FindPSResourceError" ,
287- ErrorCategory . NotSpecified ,
288- this ) ) ;
245+ versionType = VersionType . NoVersion ;
246+ }
247+
248+ foreach ( PSResourceInfo pkg in _findHelper . FindByResourceName (
249+ name : Name ,
250+ type : Type ,
251+ versionRange : versionRange ,
252+ nugetVersion : nugetVersion ,
253+ versionType : versionType ,
254+ version : Version ,
255+ prerelease : Prerelease ,
256+ tag : Tag ,
257+ repository : Repository ,
258+ includeDependencies : IncludeDependencies ,
259+ suppressErrors : false ) )
260+ {
261+ WriteObject ( pkg ) ;
289262 }
290263 }
291264
0 commit comments