| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Rather than removing this test, can you skip it for non-windows platforms?
Sorry, something went wrong.
There was a problem hiding this comment.
The idea (from Jason Shirk (@lzybkr)) is that we should put all alias tests in one place (Default-Aliases.Tests.ps1) rather than spread on many files.
Sorry, something went wrong.
|
Ilya (@iSazonov) thanks for the fix! PS /> Get-Alias | ? { gcm $_.Definition -ea SilentlyContinue > $null; !$? }
CommandType Name Version Source
----------- ---- ------- ------
Alias gin -> Get-ComputerInfo 3.1.0.0 Microsoft.PowerShe...
Alias gsv -> Get-Service
Alias sasv -> Start-Service
Alias spsv -> Stop-Service
|
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) I am glad to fix this aliases too while the ears in this. Now I catched interensting issue with "gin" alias. Please help me understand. As for Get-Service cmdlet I add the alias in InitialSessionState.cs and remove from .psd1 files. After that I start PowerShell, ipmo .\Build.psm1 and get error "AllScope option cannot be removed from the alias 'gin'". CI tests is failed too as you see. Then I remove [Alias("gin")] from GetComputerInfoCommand.cs - now all work well.
|
Sorry, something went wrong.
What I would do is:
For cmdlets like *-Clipboard, they have already been excluded from the build in powershell core. You can take a look at the .csproj file of the corresponding project. Basically, there are also 4 aliases that are currently exposed on unix plats by mistake. You can run the following command to observe. Get-Alias | ? { gcm $_.Definition -ea SilentlyContinue > $null; !$? }
CommandType Name Version Source
----------- ---- ------- ------
Alias gin -> Get-ComputerInfo 3.1.0.0 Microsoft.PowerShe...
Alias gsv -> Get-Service
Alias sasv -> Start-Service
Alias spsv -> Stop-Service
|
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) Thanks! I still don't understand
Jason Shirk (@lzybkr) Could you please comment too? |
Sorry, something went wrong.
Yes, we can have a test for it. Basically, we need to get the list of types that shouldn't be available on different platforms, for example, [Microsoft.PowerShell.Commands.GetComputerInfoCommand] should fail on Unix plats.
Declaration of aliases in InitialSessionState.cs came from the days before [Alias] attribute was made supported for command types (previously [Alias] was only supported for parameters). So they are legacy code. For new cmdlet code, AliasAttribute should be used. For the legacy code, I'm inclined to keep them that way, as I'm not sure if changing them would cause some unobvious regression. For new cmdlet implementation, I think AliasAttribute is the way to go. |
Sorry, something went wrong.
|
Can we create new attribute like Platform("Unix") to mark cmdlet classes? Can this approach make our tests easier? What unobvious regression you expect with aliases? I believe that there is no functional code which we can break down, no new code. On the other hand, if we move the aliases in cmdlets ([Alias]) we get rid of some of the complexities that are trying to fix here. |
Sorry, something went wrong.
Those alias declarations are publicly accessible, via InitialSessionState.Commands. For example: PS> $iis = [initialsessionstate]::CreateDefault()
PS> $iis.Commands.Name | ? { $_ -eq 'gps' }
gps
So it's hard to anticipate how people will depend on them ... that's why I said unobviously regression.
A class that should be excluded from a platform may not be a cmdlet, so I don't think a new attribute will help. Not excluding a file that is supposed to be excluded on a platform won't be a big issue really. I think we can just fix it when it comes up. |
Sorry, something went wrong.
|
Clear about new attribute. I tried to add gin alias to InitialSessionState.cs and use Alias('gin')] (the code add cmdlet aliases in a session) - in both cases, I see the alias in a session state. Both options work equally. So it looks safe if we move the cmdlet aliases in cmdlets and exclude the files (or the aliases) with #if !UNIX and #endif if we need. The only public change will be (not breaking change) that we will remove aliases that should not be there (aliases for not ported cmdlets or aliases unwanted on Unix) and add the ones we want to appear. So users get right thinks with [initialsessionstate]::CreateDefault(). |
Sorry, something went wrong.
|
Ilya (@iSazonov) thanks for the extra validation exercise! Then I'm fine moving the aliases from InitialSessionState to individual cmdlets. Do you want to do that in a separete PR or address all in this PR? |
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) Thanks for approve! I believe we can continue here to preserve the usefull discussion. I have already started to prepare new tests. |
Sorry, something went wrong.
|
I created new file with tests to check default alias and cmdlet lists. Dongbo Wang (@daxian-dbw) Please review the test. After that the way will be open for safe code edits. |
Sorry, something went wrong.
There was a problem hiding this comment.
"nwsn -> New-PSWorkflowSession" = $FullCLR
I don't see this alias on windows powershell ...
PS:4> Get-Alias -Definition New-PSWorkflowSession
Get-Alias : This command cannot find a matching alias because an alias with the definition 'New-PSWorkflowSession'
does not exist.
At line:1 char:1
+ Get-Alias -Definition New-PSWorkflowSession
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-PSWorkflowSession:String) [Get-Alias], ItemNotFoundException
+ FullyQualifiedErrorId : ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand
Environment
Name Value
---- -----
PSVersion 5.1.14393.1066
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1066
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Sorry, something went wrong.
There was a problem hiding this comment.
😕 I see on 10.0.10240 and on 10.0.16179
Sorry, something went wrong.
There was a problem hiding this comment.
My bad. It's defined in the module PSWorkflow which is not loaded by default. Let's keep it in the list.
Sorry, something went wrong.
There was a problem hiding this comment.
gtz is also available in windows powershell.
Sorry, something went wrong.
There was a problem hiding this comment.
No on 10.0.10240
Sorry, something went wrong.
There was a problem hiding this comment.
PS:3> Get-Alias gtz CommandType Name Version Source ----------- ---- ------- ------ Alias gtz -> Get-TimeZone 3.1.0.0 Microsoft.PowerShell.Manag...
Available in 10.0.14393.1066
Name Value
---- -----
PSVersion 5.1.14393.1066
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1066
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Sorry, something went wrong.
There was a problem hiding this comment.
What version we should use as a base?
Sorry, something went wrong.
There was a problem hiding this comment.
don't show full list wrong aliases
doesn't show the list of different aliases
Sorry, something went wrong.
There was a problem hiding this comment.
This comment hasn't been addressed yet.
Sorry, something went wrong.
There was a problem hiding this comment.
We should remove this from Default-Aliases.Tests.ps1 as the last step in the PR.
Sorry, something went wrong.
There was a problem hiding this comment.
sounds good.
Sorry, something went wrong.
|
Ilya (@iSazonov) the test looks mostly good. I left a few comments. |
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) I fixed the original list of aliases.
|
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) - Please take another look. |
Sorry, something went wrong.
|
Ilya (@iSazonov) sorry for coming back so late.
I agree the alias option settings there seem a bit messed up, for example, aliases for *-PSSession cmdlets should be consistent in my opinion.
Yep, AliasAttribute now doesn't set any options to an alias, which seems by design to me, because we don't want the module author to decide if their alias definition should be copied to all scopes or can never be changed by the user. For a module cmdlet, a user should be the one to make that decision. PowerShell defines some alias as 'AllScope' or 'ReadOnly' because they are core cmdlets and probably shouldn't be randomly altered by the user.
This can be explained by the same dir example I gave above. It sounds like very common for people to set sls to point to a different function/utility. With AllScope, you have to write Set-Alias ... -Option AllScope to make it work, which is annoying. I think that's why it was made None option. It turns out there are good reasons to keep alias declarations in InitialSessionState.cs. I suggest we go back to the proposal I made in #3595 (comment) |
Sorry, something went wrong.
|
Ilya (@iSazonov) - Please update the PR title and description to reflect the current state of the PR. This PR has slowly moved beyond the original intent and I'd like that reflected in the title and description. |
Sorry, something went wrong.
Fix 'gsv','sasv' and 'spsv' Fix 'fhx' alias Fix 'cfs' alias Fix 'gcb' and 'scb' aliases Fix 'gtz' and 'stz' aliases Fix 'gin'
|
Mike Richmond (@mirichmo) the PR title and description was updated. Dongbo Wang (@daxian-dbw) Thanks for great comments! I moved aliases to InitialSessionState.cs |
Sorry, something went wrong.
| /// </summary> | ||
| [Cmdlet(VerbsCommon.Get, "ComputerInfo", | ||
| HelpUri = "https://go.microsoft.com/fwlink/?LinkId=799466")] | ||
| [Alias("gin")] |
There was a problem hiding this comment.
I don't think we should move gin to InitialSessionState.cs. I think for all aliases that are declared using Alias() attribute, we should keep them that way. They are not core cmdlets, and I don't see a problem to have them with 'None' option.
Sorry, something went wrong.
There was a problem hiding this comment.
For those aliases that are already declared in InitialSessionState.cs, I prefer to keep them there for now, for the sake of backward compatibility.
For those aliases that are declared with AliasAttribute, I also prefer to keep them that way unless it's a core cmdlet that should be set with options other than 'None'.
Sorry, something went wrong.
There was a problem hiding this comment.
I have found no other [Alias()] in the repo. So we should keep consistency and use the same approach - place aliases in InitialSessionState.cs.
Also I set ReadOnly because later we can replace it on None based on feedback but changing None to ReadOnly will be breaking change.
Sorry, something went wrong.
There was a problem hiding this comment.
For those aliases that are already declared in InitialSessionState.cs, we should keep them there for backward compatibility. For new aliases, I believe they should be declared using AliasAttribute, unless there is an explicit reason to set it with an option other than None.
Sorry, something went wrong.
There was a problem hiding this comment.
Should we ignore here performance of PowerShell Core start-up?
Sorry, something went wrong.
There was a problem hiding this comment.
My opinion doesn't stem from the performance concern. I just think we should no longer keep stuffing unnecessary settings to InitialSessionState.cs. Keep alias declaration in individual cmdlet is good for at least 2 reasons:
For those existing alias declarations in InitialSessionState.cs, we cannot move them out due to the ScopeItemOption settings (BTW, I think for some of the aliases there, the authors probably just copied the existing options without knowing if they should actually be applied). But for new aliases, I think it's better to have them coupled with the cmdlet unless an option other than 'none' is really desired.
Sorry, something went wrong.
There was a problem hiding this comment.
There are other benefits to the Alias attribute:
function DoIt($createArg)
{
[powershell]::Create($createArg).
AddScript('$ExecutionContext.InvokeCommand.GetCommand("clc", "Alias")').
Invoke()
}
DoIt ([System.Management.Automation.RunspaceMode]::NewRunspace)
DoIt ([System.Management.Automation.RunspaceMode]::CurrentRunspace)
$iss = [InitialSessionState]::Create()
$iss.ImportPSModule('Microsoft.PowerShell.Management')
$iss.LanguageMode = 'FullLanguage'
DoIt $issThis prints:
CommandType Name Version Source ----------- ---- ------- ------ Alias clc -> Clear-Content Alias clc -> Clear-Content
Note - only 2 results instead of 3. This is a little weird because Clear-Content is in Microsoft.PowerShell.Management, so why isn't clc?
We should perhaps consider adding support for AllScope/ReadOnly in the Alias attribute, perhaps as an internal only option so that it isn't abused.
Sorry, something went wrong.
There was a problem hiding this comment.
Dongbo Wang (@daxian-dbw) Jason Shirk (@lzybkr) Thanks for clarify!
So a plan is:
1.In the PR make a fix as Dongbo Wang (@daxian-dbw) requested
2.Open new Issue (to get feedback for removing AllScope) and then new PR to add internal only option to add support for AllScope/ReadOnly in the Alias attribute and migrate (1) alias and (2) cmdlet declarations from InitialSessionState.cs to modules.
Is it Ok?
Sorry, something went wrong.
There was a problem hiding this comment.
Sounds like a plan. When creating the new issue, please make sure all our discussion here are captured in the issue. Thanks Ilya (@iSazonov)!
Sorry, something went wrong.
There was a problem hiding this comment.
Done #3796
Sorry, something went wrong.
| /// </summary> | ||
| [Cmdlet(VerbsCommon.Get, "TimeZone", DefaultParameterSetName = "Name", | ||
| HelpUri = "https://go.microsoft.com/fwlink/?LinkId=799468")] | ||
| [Alias("gtz")] |
There was a problem hiding this comment.
Same to gtz and stz in TimeZoneCommands.cs
Sorry, something went wrong.
| { | ||
| // We add aliases from custom modules with 'ScopedItemOptions.None' | ||
| // because only a module consumer (not the module author) decides | ||
| // whether the alias is read only and available in all scopes. |
There was a problem hiding this comment.
These comments actually should go to AliasAttribute.
Sorry, something went wrong.
There was a problem hiding this comment.
Move the comment or copy?
Sorry, something went wrong.
There was a problem hiding this comment.
My bad. This comment should be put here.
However, the comment may need a bit change, since AliasAttribute can be used in built-in module, not custom modules only. Maybe the following is a little better:
"Alias declared by AliasAttribute is set with the option 'ScopedItemOptions.None', because we believe a user of the cmdlet, instead of the author of it, should be the one to decide the option of the alias usage."
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe:
"Alias declared by AliasAttribute is set with the option 'ScopedItemOptions.None', because we believe a user of the cmdlet, instead of the author of it, should be the one to decide the option ('ScopedItemOptions.ReadOnly' and/or 'ScopedItemOptions.AllScopes') of the alias usage."
Sorry, something went wrong.
There was a problem hiding this comment.
Sounds good 👍
Sorry, something went wrong.
| @@ -1,4 +1,6 @@ | |||
| using System; | |||
| #if !CORECLR | |||
There was a problem hiding this comment.
GetClipboardCommand.cs and SetClipboardCommand.cs are currently not included in the build (see here). We use those excluded compile entries in csproj files as a living document to track what built-in cmdlets are not in powershell core yet. So the if/def CORECLR is not necessary in those files.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
|
If we shall move alias definitions to multiple files (modules) maybe add tests in DefaultCommands.Tests.ps1 to check alias's ScopedItemOptions? |
Sorry, something went wrong.
| /// Displays the hexidecimal equivalent of the input data. | ||
| /// </summary> | ||
| [Cmdlet(VerbsCommon.Format, "Hex", SupportsShouldProcess = true, HelpUri ="https://go.microsoft.com/fwlink/?LinkId=526919")] | ||
| [Alias ("fhx")] |
There was a problem hiding this comment.
This alias declaration shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, sorry. Fixed.
Sorry, something went wrong.
| "Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug", | ||
| "Get-RunspaceDebug", "Wait-Debugger" , "Get-Uptime", "New-TemporaryFile", "Get-Verb", "Format-Hex" | ||
| FunctionsToExport= "Import-PowerShellDataFile" | ||
| AliasesToExport= "fhx" |
There was a problem hiding this comment.
This shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
Why? Currently Format-Hex cmdlet is binary. I believe it was left from the time when the cmdlet was function.
Furthermore we now control all the aliases in the tests and can safely export all aliases by default.
Sorry, something went wrong.
There was a problem hiding this comment.
If alias is not declared in .psd1 file, using the alias when the module hasn't been loaded will not trigger the module autoloading. Try the following and you will see it:
PS:44> gmo | rmo
PS:45> gmo
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
PS:46> gin
gin : The term 'gin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gin
+ ~~~
+ CategoryInfo : ObjectNotFound: (gin:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Sorry, something went wrong.
There was a problem hiding this comment.
Is the behavior different from cmdlets export?
If we move aliases from InitialSessionState.cs we should add all ones to psd1?
gcm | ? Source -eq "Microsoft.PowerShell.Management" | % {Get-Alias -Definition $_.Name -ErrorAction SilentlyContinue}
Sorry, something went wrong.
There was a problem hiding this comment.
Is the behavior different from cmdlets export?
Not sure what you mean by "cmdlet export".
If we move aliases from InitialSessionState.cs we should add all ones to psd1?
From what I observed, it seems to be so. But it feels natural to me -- module should control what aliases to expose, and it's more discoverable if the .psd1 files always tell the complete truth.
Sorry, something went wrong.
There was a problem hiding this comment.
Not sure what you mean by "cmdlet export".
Defaults is AliasesToExport="" and CmdletsToExport="". For first case the module autoload don't works, for second it works?
Sorry, something went wrong.
There was a problem hiding this comment.
No, it won't work. If you remove a cmdlet from the "CmdletsToExport" then that cmdlet will not be exposed from the module.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for clarify! It seems I confused with the IntelliSense behavior.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| PowerShellVersion="3.0" | ||
| NestedModules="Microsoft.PowerShell.Commands.Management.dll" | ||
| HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=390785' | ||
| AliasesToExport = @("gin", "gtz", "stz") |
There was a problem hiding this comment.
This shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
The same - we now control all the aliases in the tests and can safely export all aliases by default.
Sorry, something went wrong.
There was a problem hiding this comment.
Same reason as explained above.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| "Unblock-File", "Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug", | ||
| "Get-RunspaceDebug", "Wait-Debugger" , "Get-Uptime", "Get-Verb", "Format-Hex" | ||
| FunctionsToExport= "ConvertFrom-SddlString" | ||
| AliasesToExport= "fhx" |
There was a problem hiding this comment.
This shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
The same - we now control all the aliases in the tests and can safely export all aliases by default.
Sorry, something went wrong.
There was a problem hiding this comment.
Same reason as explained above.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| CLRVersion="4.0" | ||
| NestedModules="Microsoft.PowerShell.Commands.Management.dll" | ||
| HelpInfoURI = 'https://go.microsoft.com/fwlink/?linkid=390785' | ||
| AliasesToExport = @("gcb", "scb", "gin", "gtz", "stz") |
There was a problem hiding this comment.
Shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
The same - we now control all the aliases in the tests and can safely export all aliases by default.
Sorry, something went wrong.
There was a problem hiding this comment.
Same reason as explained above.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Same here. Shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
Previous test do that so the test is alias related only.
Sorry, something went wrong.
There was a problem hiding this comment.
#Closed
Sorry, something went wrong.
|
|
||
| $var1 | Should Be #nothing. it should be Nothing at all. | ||
|
|
||
| } |
There was a problem hiding this comment.
same here. Shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
Previous test do that so the test is alias related only.
Sorry, something went wrong.
There was a problem hiding this comment.
#Closed
Sorry, something went wrong.
| it "Should return an array data type when multiple matches are found" { | ||
| $result = $testinputtwo | Select-String -Pattern "hello" | ||
| ,$result | Should BeOfType "System.Array" | ||
| } |
There was a problem hiding this comment.
Same here. Both tests shouldn't be removed.
Sorry, something went wrong.
There was a problem hiding this comment.
The first - Previous test do that so the test is alias related only.
The second is not removed - it is below - diff trick 😕
Sorry, something went wrong.
There was a problem hiding this comment.
#Closed
Sorry, something went wrong.
| # instead of Get-Alias and Get-Command | ||
| # but latest is more simple use. | ||
| #$iis = [initialsessionstate]::CreateDefault() | ||
| #$currentCmdletList = $iis.Commands | Where-Object { $_.CommandType -eq "Cmdlet"} | Select-Object -ExpandProperty Name |
There was a problem hiding this comment.
These comments don't seem necessary to keep.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes. Removed.
Sorry, something went wrong.
| # if all aliases is Ok we output nothing | ||
| $result | Write-Host | ||
| $result | Should Be $null | ||
| } |
There was a problem hiding this comment.
Isn't this test the same as the one in Default-Aliases.Tests.ps1? Are you planning to remove Default-Aliases.Tests.ps1 and replace it with this file?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, I'll remove the duplication. I leave it for easy review and for checking new tests in DefaultCommands.Tests.ps1.
Sorry, something went wrong.
That sounds great. |
Sorry, something went wrong.
|
Ilya (@iSazonov) The changes look good to me, and special thanks for the new tests covering the complete list of built-in aliases/cmdlets! |
Sorry, something went wrong.
New commits have been pushed
|
Dongbo Wang (@daxian-dbw) I removed Default-Aliases.Tests.ps1 and move test for more to DefaultCommands.Tests.ps1 (Remaining tests looks as duplications) |
Sorry, something went wrong.
|
Dongbo Wang (@daxian-dbw) Thanks for help and great comments! |
Sorry, something went wrong.
…3595) Make changes to not expose the aliases "gin", "gsv", "sasv" and "spsv" in Unix platforms. Also refactored aliases related tests and added new tests covering the complete list of built-in aliases/cmdlets.
| Back | FazBrowse Home | New Git URL |
Fix #3577.
Make changes to not expose the aliases "gin", "gsv", "sasv" and "spsv" in Unix platforms.
Also refactored aliases related tests and added new tests covering the complete list of built-in aliases/cmdlets.