Skip to content

Make Get-ChildItem honor Depth parameter with Include/Exclude - #4985

Merged
Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
Windos:gci-recurse-exclude-include
Oct 23, 2017
Merged

Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
Windos:gci-recurse-exclude-include

Conversation

@Windos

Copy link
Copy Markdown
Contributor

Addresses issue #3726 by adding decrementing depth to ProcessPathItems.

Includes tests specifically for the examples listed in the issue and also testing that recursion still works when excluding or including a string.

Honors capped recursion when using Include or Exclude filters with Get-ChildItem

int unUsedChildrenNotMatchingFilterCriteria = 0;
ProcessPathItems(providerInstance, providerPath, recurse, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate);
ProcessPathItems(providerInstance, providerPath, recurse, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate, depth: depth);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to exclude parameters with defaults and use overloads.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just pushed new commit swapping optional parameter for overload. Is it along the right track?

@iSazonov

Ilya (iSazonov) commented Oct 4, 2017 •

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Can we ask Josh King (@Windos) to fix (replace with overloads) skipIsItemContainerCheck defaults in the PR? It seems adding new parameter (depth) complicate the Api and it would be good to eliminate that now.

@daxian-dbw

Copy link
Copy Markdown
Member

Well, the optional parameter was introduced to be an alternative of overloads, to reduce the number of overloads of a method.
If we remove skipIsItemContainerCheck by adding overloads, then there will be 4 overloads of ProcessPathItems, which IMHO might be cumbersome.

The optional parameter should never be used for public APIs or even internal APIs that may be called from other friend assemblies because the default value is baked into the caller, and that means if we change the default value, the caller assembly needs to be re-compile to get the new default value.
However, it's fine for private methods, as long as it doesn't affect readability much.

@iSazonov

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) I asked because adding second optional parameter reduced readability. Do we have to create overloads in this case or can we just replace its with one method with all the parameters?

@Windos

Copy link
Copy Markdown
Contributor Author

I'm happy to put the work in regardless of which direction is decided on.

@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@iSazonov) I think you made the right call. Adding the second optional parameter would worsen the readability. I think the current two overloads look good.

@adityapatwardhan

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Dongbo Wang (@daxian-dbw) can you update your review

@iSazonov

Ilya (iSazonov) commented Oct 9, 2017 •

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Is uint depth parameter on best place? What about before last?

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.

LGTM

@adityapatwardhan

Copy link
Copy Markdown
Member

Dongbo Wang (@daxian-dbw) Can you update your review?

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit c98fe39 into PowerShell:master Oct 23, 2017
@adityapatwardhan

Copy link
Copy Markdown
Member

Josh King (@Windos) Thanks for your contribution!

@vors
sergei (vors) removed their request for review October 24, 2017 04:59
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…hell#4985)

* Add depth to ProcessPathItems

* Honors capped recursion when using Include or Exclude filters with Get-ChildItem

* Including test cases to test include/exclude recursion

* Swap optional parameter for overload
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.

4 participants