-
Notifications
You must be signed in to change notification settings - Fork 59
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
Populate FunctionsToExport with explicit list of commands #205
Comments
The module determines exported commands in runtime depending on client capabilities to avoid exporting functions that technically cannot be executed in a particular session. As the result, the list of exported functions is dynamic and cannot be statically populated in |
Would it not be more useful then to publish all commands and fail the ones whose requirements are not met? |
Exporting functions with an '*' in the manifest file will cause PowerShell not recognize the function if PowerShell is running in constrained language mode. Each function must be explicitly listed as is currently being done. |
That's what I wanted to avoid. Otherwise, I will have to write platform/dependency support check in every function and this will add confusion: the command exist, but cannot run. |
I'd argue on the confusion part - not whether it will happen, but which of the two possible points of confusion are worse (since you don't get to pick an option that is 100% confusion free for everybody).
Given that the target audience is likely to be CA admins rather than PowerShell experts, I believe that the "Command cannot be used" problem is a lot easier to explain or understand. As for the implementation headache - I strongly recommend implementing assertions for that kind of situation:
function Assert-Something {
<#
.SYNOPSIS
Assert that something is true.
.DESCRIPTION
Assert that something is true.
.PARAMETER Cmdlet
The $PSCmdlet variable of the calling command.
.EXAMPLE
PS C:\> Assert-Something -Cmdlet $PSCmdlet
Assert that something is true.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
$Cmdlet
)
process {
if ("Something" -is $true) {
return
}
$exception = [System.InvalidOperationException]::new("Invalid environment! This command can only run if XYZ is true!")
$record = [System.Management.Automation.ErrorRecord]::new($exception, "InvalidEnvironment", [System.Management.Automation.ErrorCategory]::InvalidOperation, $null)
$Cmdlet.ThrowTerminatingError($record)
}
}
Assert-Something -Cmdlet $PSCmdlet With that you have one central place where you implement both code and error message, the actual impact on your individual commands' complexity is minimal. The internas are hidden from the user and you can use the error message to usefully complain what is the issue, so the confusion should be minimal. Thank you for taking the time on this issue, whether I managed to convince you or not (it is a matter of perspectives and priorities, so I'm hardly going to judge either way). |
Hi,
thanks for the awesome project! I've got a small feature request:
Could you - going forward - update your PSPKI.psd1 on release to no longer include
FunctionsToExport = '*'
and instead list each command individually?The wildcard is convenient as you develop, but it has some problems when trying to run the module in a hardened environment and it makes discovery a pain.
For example, I can search for all modules on the gallery that contain a given command:
As of now, there's one module that's not going to be found ...
The text was updated successfully, but these errors were encountered: