8000 PowerShell needs a way to hide commands which won't work · Issue #1998 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

PowerShell needs a way to hide commands which won't work #1998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jaykul opened this issue Aug 21, 2016 · 12 comments
Closed

PowerShell needs a way to hide commands which won't work #1998

Jaykul opened this issue Aug 21, 2016 · 12 comments
Labels
Committee-Reviewed PS-Committee has reviewed this and made a decision Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime
Milestone

Comments

@Jaykul
Copy link
Contributor
Jaykul commented Aug 21, 2016

For example: Set-ExecutionPolicy. This command should simply not exist on Linux. Rather than throwing RuntimeErrorException terminating errors, I would prefer to get a command-not found, because that's something I can test for ahead of time.

Years of developing for moving targets on the web has taught us that the right way to avoid features that don't exist is to test for the feature, and not for the underlying OS, Architecture, or software version, because you never know when someone's going to finally figure out how to implement something.

If non-functioning commands are not hidden, there is no easy, fast way for scripts to test for whether commands will work -- you have to run them and catch the exception. However, many scripters will instead write incorrect conditional code based on the PSEdition (or operating system sniffing, but currently that's not even in $PSVersionTable #1997) which will prevent them from using the feature in the case where it's added later on.

In general, when a (core) module exposes a command (functioning or not), it's more difficult for another module to provide an implementation -- I know we can't anyway in this particular example, but that's the problem with picking examples ;-)

Suggestion: This should be exposed in the manifest.

I would like an easy way to identify commands that should be exported based on PSEdition, PSVersion, OS, or Architecture from the module manifest.

I don't want to have to wrap binary modules in script modules to put conditional Export-ModuleManifest statements in ... especially since putting the right values in the manifest for exported cmdlets is vital to discoverability.

One thought is to allow specific module manifests for platforms, like MyModule.Core-Linux.psd1 or something -- this would provide solutions to other design problems as well (like loading the right binary assemblies).

@lzybkr
Copy link
Contributor
lzybkr commented Aug 21, 2016

The plan is to allow the variables $IsLinux and $IsWindows so you can use something like:

CmdletsToExport = "Get-Process",$(if ($IsWindows) { "Set-ExecutionPolicy" })

@kilasuit
Copy link
Collaborator

Although I agree this needs to be in the Module Manifest I think that we need to have this information in the Cmdlet (or Function) as an additional property that we can define perhaps like so

[CmdletBinding(SupportedOsVersions='Windows','Linux','MacOS')]

(not sure would need MacOS but best to put it in there)

I believe that would be a breaking change but would allow for CI systems to dynamically build the *ToExport lists like @lzybkr has suggested for in the Manifest

@Jaykul
Copy link
Contributor Author
Jaykul commented Aug 23, 2016

It would be convenient to be able to do it with an attribute, but unless putting it in the CmdletBinding attribute automatically hides it, it should not go there at all.

I'm ok with the $IsWindows and $IsLinux but can we also access $IsCore or $IsARM ?

@Se1ecto
Copy link
Se1ecto commented Aug 23, 2016

Something could be done using the "Get-CimInstance" cmd, if it works on Linux, of course.
GitHub noob contributor here.

@masaeedu
Copy link

@lzybkr Would this help us with intellisense when e.g. developing scripts for Linux from an instance of VSCode running on Windows?

@SteveL-MSFT SteveL-MSFT added the WG-Engine core PowerShell engine, interpreter, and runtime label Sep 29, 2016
@SteveL-MSFT SteveL-MSFT added this to the 6.0.0 milestone Sep 29, 2016
@SteveL-MSFT SteveL-MSFT modified the milestones: 6.0.0-beta, 6.0.0 Dec 19, 2016
@SteveL-MSFT SteveL-MSFT modified the milestones: 6.0.0-beta2, 6.0.0-beta1 Mar 18, 2017
@SteveL-MSFT SteveL-MSFT modified the milestones: 6.0.0-beta, 6.0.0 May 15, 2017
@joeyaiello joeyaiello modified the milestones: 6.0.0-HighPriority, 6.0.0 May 25, 2017
@SteveL-MSFT SteveL-MSFT modified the milestones: 6.1.0, 6.0.0-HighPriority Aug 31, 2017
@SteveL-MSFT
Copy link
Member

We need to spend more time thinking through the solution (perhaps a RFC), moving to 6.1.0

@mi-hol
Copy link
mi-hol commented Feb 17, 2018

@SteveL-MSFT did the thinking bear fruit that could be shared here?

@SteveL-MSFT
Copy link
Member

@mi-hol no investigation for this has happened yet

@bcdady
Copy link
bcdady commented Dec 13, 2018

I am running PowerShell Core 6.1.1 on MacOS, and encountered these symptoms again. I found this issue via #7573.
I run Get-ExecutionPolicy in $PROFILE Script, which works fine, but then I instinctively want to go run Set-ExecutionPolicy, which doesn't work.

I could add more specific issues to running Set-ExecutionPolicy in PS Core on MacOS, but for this Issue, I think this is sufficient.

@SteveL-MSFT SteveL-MSFT added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Jan 9, 2019
@SteveL-MSFT
Copy link
Member

Module manifest already supports conditional exporting https://docs.microsoft.com/en-us/powershell/gallery/concepts/module-psedition-support

As for the ExecutionPolicy cmdlets themselves, I don't recall exactly why we left them since we explicitly removed others. Let's have Committee review.

@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee reviewed this, since we want to retain Get-ExecutionPolicy for compatibility reasons (and should return Bypass which is more accurate on non-Windows). It would make sense to keep Set-ExecutionPolicy and only allow setting Unrestricted or Bypass, other values should continue to return the Operation not supported on this platform error. pwsh -executionpolicy should also follow this.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jan 9, 2019
@iSazonov
Copy link
Collaborator

It seems we hide/remove all that don't work on Unix-s. Can we close the issue?

@SteveL-MSFT SteveL-MSFT added the Resolution-Fixed The issue is fixed. label Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committee-Reviewed PS-Committee has reviewed this and made a decision Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

10 participants
0