question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DontShow should not hide common parameters

See original GitHub issue

Summary of the new feature / enhancement

The DontShow attribute parameter that the Parameter attribute has allows a function/script author to hide parameters like this:

function Verb-Noun
{
    Param
    (
        [Parameter()]
        [string]
        $Param1,

        [Parameter(DontShow)]
        [string]
        $Param2
    )
}
#Tab completion does not show Param2
Verb-Noun -<Tab>

This has the side effect of also hiding the common parameters.
It seems to have been an intentional design choice, see this: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L768 but I think that should be changed because it makes it impractical to use DontShow to hide old deprecated parameters like ConvertTo-Csv does with the NoTypeInformation parameter because then the user won’t see important common parameters like ErrorAction.

Proposed technical implementation details (optional)

Instead of automatically hiding common parameters when DontShow has been specified, add a HideCommonParameters parameter to the CmdletBinding attribute.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MartinGC94commented, Nov 11, 2022

Sure you can, but then you miss out on pipeline support, parametersets, and mandatory parameters.

Then you want an advanced function/script and not a simple function / script which again comes back to a more important question on function/script design. which is a much larger question than many realise until later on in the development of it & often changes drastically over time.

So what’s your point here? That nobody would want to hide the common parameters for a random script with a mandatory parameter?
I’m sure I’m not the only one that has done something like this in a script where I needed a mandatory parameter but didn’t want to confuse the user with the common parameters:

Param
(
    [Parameter(Mandatory)]
    [string]
    $Param1,

    # Dummy parameter to hide common parameters
    [Parameter(DontShow)]
    $Dummy
)

Just to be clear here, I’m obviously not arguing to keep the current behavior, I’m just saying that if we fix the current behavior we need to provide an alternative for the people that actually wants to hide common parameters.

0reactions
MartinGC94commented, Jun 21, 2023

@theJasonHelmick Any update from the working group?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use PowerShell to Hide Parameter From IntelliSense
Introduced in Windows PowerShell 4.0, you can specify the DontShow attribute for the [parameter()] type to hide that parameter from ...
Read more >
How to hide a parameter from Get-Help (not just tab ...
Declare this parameter with both the DontShow and ValueFromRemainingArguments [Parameter()] properties. Manually check the argument(s) bound to ...
Read more >
Designing Professional Parameters - powershell.one
Hiding Parameters. Let's finish this article by looking at a lesser-known attribute value: DontShow. It hides parameters from Intellisense and ...
Read more >
The DontShow property - Mastering Windows PowerShell ...
The DontShow property DontShow may be used to hide a parameter from tab completion and IntelliSense. This property is rarely used, but may...
Read more >
Hide arguments to program without source code
I need to hide some sensitive arguments to a program I am running, but I don't have access to the source code. I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found