Skip to content

Add ShouldProcess to New-FileCatalog and Test-FileCatalog - #3074

Merged
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
iSazonov:newfilecatalogwhatif
Feb 18, 2017
Merged

Add ShouldProcess to New-FileCatalog and Test-FileCatalog#3074
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
iSazonov:newfilecatalogwhatif

Conversation

@iSazonov

Copy link
Copy Markdown
Collaborator

Close #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.

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;

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paul Higinbotham (@PaulHigin) Good catch!
Jason Shirk (@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'?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed _ShouldProcess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paul Higinbotham (@PaulHigin) I think your comment has been addressed

try
{
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -WhatIf
$result = Test-Path -Path ($catalogPath + "\catalog.cat")

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

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
@TravisEz13
Travis Plunk (TravisEz13) merged commit e10cbff into PowerShell:master Feb 18, 2017
@iSazonov
Ilya (iSazonov) deleted the newfilecatalogwhatif branch February 20, 2017 07:15
@iSazonov Ilya (iSazonov) removed the Review - Needed The PR is being reviewed label Mar 27, 2017
@iSazonov Ilya (iSazonov) added the Documentation Needed in this repo Documentation is needed in this repo label Jun 17, 2017
@joeyaiello Joey Aiello (joeyaiello) removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…#3074)

* Add ShouldProcess to New-FileCatalog and Test-FileCatalog

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.

* Fiz after code review

Remove  _ShouldProcess
Add var in test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants