-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add ShouldProcess to New-FileCatalog and Test-FileCatalog #3074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Close PowerShell#3068 Add support `-WhatIf` and `-Confirm` to `New-FileCatalog` and add a test. `Test-FileCatalog` has a common code base with `New-FileCatalog` so it automatically get the same. I believe that adding a separate test in this case doesn't make sense.
|
|
||
| Collection<string> paths = new Collection<string>(); | ||
|
|
||
| bool _ShouldProcess = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this boolean. You can use (paths.Count > 0) instead of (_ShouldProcess) to see if processing should continue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paul's suggestion is good, but I'm fine with a local variable as well - but the local variable should not use the convention for fields - it should be shouldProcess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PaulHigin Good catch!
@lzybkr If we take into consideration that cmdlets can work with large directories, then maybe we will remove the local variable and add a comment 'paths.Count > 0 is true only if ShouldProcess allow'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed _ShouldProcess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PaulHigin I think your comment has been addressed
| try | ||
| { | ||
| $null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -WhatIf | ||
| $result = Test-Path -Path ($catalogPath + "\catalog.cat") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would introduce a variable $catalogFile or something like that and use the variable when trying to delete the file.
I would also probably not call Remove-File if Test-Path says the file isn't there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Remove _ShouldProcess Add var in test
Close #3068
Add support
-WhatIfand-ConfirmtoNew-FileCatalogand add atest.
Test-FileCataloghas a common code base withNew-FileCatalogso itautomatically get the same. I believe that adding a separate test in
this case doesn't make sense.