Skip to content

The "d" alias on the "Directory" parameter for Get-ChildItem can never work #14700

Closed

Description

@Jaykul

If you look at the parameters of Get-ChildItem, there's an alias:

> (Get-Command Get-ChildItem).Parameters["Directory"].Aliases
ad
d

The problem is that the d alias CANNOT ever work, because the Directory parameter is dynamic, and Get-ChildItem already has a parameter that starts with "d" (the "Depth" parameter), so the -d switch always gets bound to the -Depth parameter (and the user gets prompted for an actual value).

Can we remove that alias, since it's just confusing users?

Activity

  1. added
    Needs-Triage
    on Feb 3, 2021
  2. added
    Issue-Question
    on Feb 3, 2021
  3. mklement0 commented on Feb 3, 2021

    @mklement0
    Contributor

    Good point, previously reported in #4739 (I've just closed the latter, because this issue is more focused).

    Given that binding to the static parameters seemingly always takes precedence, the lessons to be drawn for future cmdlets are:

    • Do not define aliases for dynamic parameters that are prefix matches of the static parameter names / aliases, because the latter will preempt the former.

      • Ideally - I don't know if it's feasible, given that it could only be detected at runtime - cmdlets would detect this condition and report an error.
    • Static parameters taking precedence makes sense conceptually, especially in the context of provider cmdlets, so that, say, -d is always -Depth, irrespective of what provider is targeted, and not situationally either -Depth or -Directory.

  4. added
    Issue-Bug
    Up-for-Grabs
    and removed
    Issue-Question
    Needs-Triage
    on Feb 4, 2021
  5. daxian-dbw commented on May 6, 2021

    @daxian-dbw
    Member

    Closed via #15171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions