mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Make UseAbbreviationExpansion and TempDrive official features (#9872)
This commit is contained in:
@@ -173,12 +173,8 @@ namespace System.Management.Automation
|
||||
powershell
|
||||
.AddCommandWithPreferenceSetting("Get-Command", typeof(GetCommandCommand))
|
||||
.AddParameter("All")
|
||||
.AddParameter("Name", commandName);
|
||||
|
||||
if (ExperimentalFeature.IsEnabled("PSUseAbbreviationExpansion"))
|
||||
{
|
||||
powershell.AddParameter("UseAbbreviationExpansion");
|
||||
}
|
||||
.AddParameter("Name", commandName)
|
||||
.AddParameter("UseAbbreviationExpansion");
|
||||
|
||||
if (moduleName != null)
|
||||
{
|
||||
|
||||
@@ -105,12 +105,6 @@ namespace System.Management.Automation
|
||||
new ExperimentalFeature(
|
||||
name: "PSImplicitRemotingBatching",
|
||||
description: "Batch implicit remoting proxy commands to improve performance"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSUseAbbreviationExpansion",
|
||||
description: "Allow tab completion of cmdlets and functions by abbreviation"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSTempDrive",
|
||||
description: "Create TEMP: PS Drive mapped to user's temporary directory path"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSCommandNotFoundSuggestion",
|
||||
description: "Recommend potential commands based on fuzzy search on a CommandNotFoundException"),
|
||||
|
||||
@@ -364,7 +364,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// This means it matches cmdlets where the uppercase characters for the noun match
|
||||
/// the given characters. i.e., g-sgc would match Get-SomeGreatCmdlet.
|
||||
/// </summary>
|
||||
[Experimental("PSUseAbbreviationExpansion", ExperimentAction.Show)]
|
||||
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = "AllCommandSet")]
|
||||
public SwitchParameter UseAbbreviationExpansion { get; set; }
|
||||
|
||||
|
||||
@@ -1088,18 +1088,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if (ExperimentalFeature.IsEnabled("PSTempDrive"))
|
||||
{
|
||||
PSDriveInfo newPSDriveInfo =
|
||||
new PSDriveInfo(
|
||||
DriveNames.TempDrive,
|
||||
ProviderInfo,
|
||||
Path.GetTempPath(),
|
||||
SessionStateStrings.TempDriveDescription,
|
||||
credential: null,
|
||||
displayRoot: null);
|
||||
results.Add(newPSDriveInfo);
|
||||
}
|
||||
results.Add(
|
||||
new PSDriveInfo(
|
||||
DriveNames.TempDrive,
|
||||
ProviderInfo,
|
||||
Path.GetTempPath(),
|
||||
SessionStateStrings.TempDriveDescription,
|
||||
credential: null,
|
||||
displayRoot: null)
|
||||
);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -10,33 +10,16 @@ Describe "TabCompletion" -Tags CI {
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Get-Command'
|
||||
}
|
||||
|
||||
Context "ExperimentalFeatures" {
|
||||
|
||||
BeforeAll {
|
||||
$configFilePath = Join-Path $testdrive "useabbreviationexpansion.json"
|
||||
|
||||
@"
|
||||
{
|
||||
"ExperimentalFeatures": [
|
||||
"PSUseAbbreviationExpansion"
|
||||
]
|
||||
}
|
||||
"@ > $configFilePath
|
||||
|
||||
}
|
||||
|
||||
It 'Should complete abbreviated cmdlet' {
|
||||
$res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
|
||||
$res | Should -HaveCount 1
|
||||
$res | Should -BeExactly 'Import-PowerShellDataFile'
|
||||
}
|
||||
|
||||
It 'Should complete abbreviated function' {
|
||||
$res = pwsh -noprofile -settingsfile $configFilePath -c "(TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText"
|
||||
$res.Count | Should -BeGreaterOrEqual 1
|
||||
$res | Should -BeExactly 'PSConsoleHostReadLine'
|
||||
}
|
||||
It 'Should complete abbreviated cmdlet' {
|
||||
$res = (TabExpansion2 -inputScript 'i-psdf' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText
|
||||
$res | Should -HaveCount 1
|
||||
$res | Should -BeExactly 'Import-PowerShellDataFile'
|
||||
}
|
||||
|
||||
It 'Should complete abbreviated function' {
|
||||
$res = (TabExpansion2 -inputScript 'pschrl' -cursorColumn 'pschr'.Length).CompletionMatches.CompletionText
|
||||
$res.Count | Should -BeGreaterOrEqual 1
|
||||
$res | Should -BeExactly 'PSConsoleHostReadLine'
|
||||
}
|
||||
|
||||
It 'Should complete native exe' -Skip:(!$IsWindows) {
|
||||
@@ -483,7 +466,7 @@ Describe "TabCompletion" -Tags CI {
|
||||
@{ inputStr = '$host.UI.WriteD'; expected = 'WriteDebugLine('; setup = $null }
|
||||
@{ inputStr = '$MaximumHistoryCount.'; expected = 'CompareTo('; setup = $null }
|
||||
@{ inputStr = '$A=[datetime]::now;$A.'; expected = 'Date'; setup = $null }
|
||||
@{ inputStr = 'try { 1/0 } catch {};$error[0].'; expected = 'CategoryInfo'; setup = $null }
|
||||
@{ inputStr = '$e=$null;try { 1/0 } catch {$e=$_};$e.'; expected = 'CategoryInfo'; setup = $null }
|
||||
@{ inputStr = '$x= gps pwsh;$x.*pm'; expected = 'NPM'; setup = $null }
|
||||
@{ inputStr = 'function Get-ScrumData {}; Get-Scrum'; expected = 'Get-ScrumData'; setup = $null }
|
||||
@{ inputStr = 'function write-output {param($abcd) $abcd};Write-Output -a'; expected = '-abcd'; setup = $null }
|
||||
|
||||
@@ -58,26 +58,10 @@ Describe "Get-PSDrive" -Tags "CI" {
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Experimental Feature Temp: drive" -Tag Feature {
|
||||
BeforeAll {
|
||||
$configFilePath = Join-Path $testdrive "experimentalfeature.json"
|
||||
|
||||
@"
|
||||
{
|
||||
"ExperimentalFeatures": [
|
||||
"PSTempDrive"
|
||||
]
|
||||
}
|
||||
"@ > $configFilePath
|
||||
}
|
||||
|
||||
It "TEMP: drive exists if experimental feature is enabled" {
|
||||
$res = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-PSDrive Temp"
|
||||
Describe "Temp: drive" -Tag Feature {
|
||||
It "TEMP: drive exists" {
|
||||
$res = Get-PSDrive Temp
|
||||
$res.Name | Should -BeExactly "Temp"
|
||||
$res.Root | Should -BeExactly ([System.IO.Path]::GetTempPath())
|
||||
}
|
||||
|
||||
It "TEMP: drive does not exist if experimental feature is not enabled" {
|
||||
{ Get-PSDrive Temp -ErrorAction Stop } | Should -Throw -ErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,21 +32,10 @@ Describe "Get-Command Feature tests" -Tag Feature {
|
||||
|
||||
Set-Content -Path (Join-Path $testModulesPath "test1/test1.psm1") -Value "function Import-FooZedZed {}"
|
||||
Set-Content -Path (Join-Path $testModulesPath "test2/test2.psm1") -Value "function Invoke-FooZedZed {}"
|
||||
|
||||
$configFilePath = Join-Path $testdrive "useabbreviationexpansion.json"
|
||||
|
||||
@"
|
||||
{
|
||||
"ExperimentalFeatures": [
|
||||
"PSUseAbbreviationExpansion"
|
||||
]
|
||||
}
|
||||
"@ > $configFilePath
|
||||
|
||||
}
|
||||
|
||||
It "Can return multiple results relying on auto module loading" {
|
||||
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion"
|
||||
$results = pwsh -outputformat xml -command "`$env:PSModulePath += '$testPSModulePath'; Get-Command i-fzz -UseAbbreviationExpansion"
|
||||
$results | Should -HaveCount 2
|
||||
$results.Name | Should -Contain "Invoke-FooZedZed"
|
||||
$results.Name | Should -Contain "Import-FooZedZed"
|
||||
@@ -60,20 +49,23 @@ Describe "Get-Command Feature tests" -Tag Feature {
|
||||
) {
|
||||
param($name, $expected, $module)
|
||||
|
||||
$command = "Get-Command $name -UseAbbreviationExpansion"
|
||||
|
||||
if ($module) {
|
||||
$command += " -Module $module"
|
||||
$params = @{
|
||||
UseAbbreviationExpansion = $true;
|
||||
Name = $name;
|
||||
}
|
||||
|
||||
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "$command"
|
||||
if ($module) {
|
||||
$params += @{ Module = $module }
|
||||
}
|
||||
|
||||
$results = Get-Command @params
|
||||
$results | Should -HaveCount 1
|
||||
$results.Name | Should -BeExactly $expected
|
||||
}
|
||||
|
||||
It "Can return multiple results for cmdlets matching abbreviation" {
|
||||
# use mixed casing to validate case insensitivity
|
||||
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-Command i-C -UseAbbreviationExpansion"
|
||||
$results = Get-Command i-C -UseAbbreviationExpansion
|
||||
$results.Name | Should -Contain "Invoke-Command"
|
||||
$results.Name | Should -Contain "Import-Clixml"
|
||||
$results.Name | Should -Contain "Import-Csv"
|
||||
@@ -89,18 +81,25 @@ Describe "Get-Command Feature tests" -Tag Feature {
|
||||
function Get-FB { "fb" }
|
||||
"@ > $modulePath
|
||||
|
||||
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "Import-Module $manifestPath; Get-Command g-fb -UseAbbreviationExpansion"
|
||||
$results | Should -HaveCount 2
|
||||
$results[0].Name | Should -BeExactly "Get-FB"
|
||||
$results[1].Name | Should -BeExactly "Get-FooBar"
|
||||
try {
|
||||
Import-Module $manifestPath
|
||||
$results = Get-Command g-fb -UseAbbreviationExpansion
|
||||
$results | Should -HaveCount 2
|
||||
$results[0].Name | Should -BeIn "Get-FB","Get-FooBar"
|
||||
$results[1].Name | Should -BeIn "Get-FB","Get-FooBar"
|
||||
$results[0].Name | Should -Not -Be $results[1].Name
|
||||
}
|
||||
finally {
|
||||
Remove-Module test
|
||||
}
|
||||
}
|
||||
|
||||
It "Non-existing cmdlets returns non-terminating error" {
|
||||
pwsh -settingsfile $configFilePath -command 'try { get-command g-adf -ea stop } catch { $_.fullyqualifiederrorid }' | Should -BeExactly "CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand"
|
||||
{ get-command g-adf -ErrorAction Stop } | Should -Throw -ErrorId "CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand"
|
||||
}
|
||||
|
||||
It "No results if wildcard is used" {
|
||||
pwsh -settingsfile $configFilePath -command Get-Command i-psd* -UseAbbreviationExpansion | Should -BeNullOrEmpty
|
||||
Get-Command i-psd* -UseAbbreviationExpansion | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user