Skip to content

Extend Get-Help to support focused lookup of documentation for PowerShell operators #11339

Closed

Description

See also:

Summary of the new feature/enhancement

PowerShell has a wealth of operators, many of them with sophisticated functionality, even in the case of operators familiar from other languages (e.g., * offering not just numeric multiplication, but also string replications).

To take full advantage of them, consulting the documentation is necessary, yet this documentation is currently hard to discover.

Get-Help should support an easy way to offer focused lookup of the documentation for any given operator, via the operator symbols themselves - ideally by showing / navigation to just the relevant portion of the enclosing about_*Operators* page or similar.

Proposed technical implementation details (optional)

Here's how it could work:

# WISHFUL THINKING

# Lists the names of all about_*Operators* topics.
Get-Help -Category Operator

# Opens the help topic (section) for the -replace operator.
# Allow omitting the initial '-'; if you do specify it, quote the entire argument.
Get-Help -Category Operator -Name 'replace'

# For simplicity, if the (positional) -Name argument is unambiguously an operator symbol,
# do not require -Category Operator
# Ignore whitespace in all arguments, so that, e.g., '@( )` works in addition to '@()'
Get-Help '@()'  # -Category Operator implied
Get-Help '-replace'
Get-Help '%'
Get-Help '>'
Get-Help '--%'  # not technically an operator, but we should support it too

# Quotes aren't technically operators, but we should support them too:
# All of these could open the about_Quoting_Rules topic.
Get-Help '"' # or: '""'
Get-Help "'" # or: "''"
Get-Help "@'" # or: "@''@"
Get-Help '@"' # or: '@""@'

# Ambiguous symbols
Get-Help '[]' # either default to indexer over casts / type constraints, or list both to force disambiguation
Get-Help '[0]' # interpret as indexer; also: Get-Help '["foo"]' 
Get-Help '[int]' # interpret as cast / type constraint; any non-numeric unquoted name should work

Get-Help '.' # default to member-access over dot-sourcing; print hint for how to look up dot-sourcing
Get-Help '. ' # dot-sourcing (trailing space disambiguates)

Get-Help '&' # default to call operator over background operator, print hint for how to look up the background operator
Get-Help ' &' # background operator (leading space disambiguates)

Get-Help '@' # default to splatting, but print hint for how to look up @() and @'...'@

It would also be helpful to be able to output a concise table of operators, along the following lines:

# Not sure what the best syntax is here; maybe include it in about_Operators with links to
# the operator-specific descriptions.
# Note the 'LookupName' column which shows how to resolve ambiguities.
PS> Get-Help about_OperatorTable
Name         FriendlyName                                Category        LookupName
----         ------------                                --------        ----------
--%          stop-parsing symbol                         ArgumentPassing
@            splatting                                   ArgumentPassing
-            subtraction / sign inversion                Arithmetic
*            multiplication / string replication         Arithmetic
...
+            addition / string concatenation              Arithmetic
,            array constructor                           Array
..           range (numbers/characters)                  Array
--           decrement                                   Assignment
-=           compound assignment                         Assignment
...
-band        bitwise AND                                 Bitwise
-bNot        bitwise complement                          Bitwise
...
?:           ternary conditional                         Conditional
??           null-coalescing                             Conditional
-contains    collection contains RHS                     Containment
-in          LHS contained in RHS                        Containment
-notContains collection doesn't contain RHS              Containment
-notIn       LHS not contained in collection             Containment
-eq          equality                                    Equality
-ge          greater-than-or-equal                       Equality
# ...
@()          array-subexpression                         Evaluation
$()          subexpression                               Evaluation
.            (dot-)source                                Execution       '. '
&            background                                  Execution       ' &'
&            call (execute)                              Execution
-and         logical AND                                 Logical
...

Note:

Activity

  1. added
    Issue-Enhancement
    on Dec 13, 2019
  2. added
    WG-Interactive-HelpSystem
    on Dec 13, 2019
  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. added
    Resolution-No Activity
    on Nov 16, 2023
  7. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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-EnhancementResolution-No ActivityWG-Interactive-HelpSystem

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions