Remove 'more' function and move the $env:PAGER capability into the help function (#6059)
This commit is contained in:
parent
145cb77226
commit
c1026b3ae8
|
@ -4250,8 +4250,12 @@ param(
|
|||
$PSBoundParameters['Full'] = $true
|
||||
}
|
||||
|
||||
# Set the outputencoding to Console::OutputEncoding. More.com doesn't work well with Unicode.
|
||||
$outputEncoding=[System.Console]::OutputEncoding
|
||||
# Nano needs to use Unicode, but Windows and Linux need the default
|
||||
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) {
|
||||
[System.Text.Encoding]::Unicode
|
||||
} else {
|
||||
[System.Console]::OutputEncoding
|
||||
}
|
||||
|
||||
$help = Get-Help @PSBoundParameters
|
||||
|
||||
|
@ -4262,7 +4266,15 @@ param(
|
|||
}
|
||||
else
|
||||
{
|
||||
$help | more
|
||||
# Respect PAGER, use more on Windows, and use less on Linux
|
||||
$moreCommand,$moreArgs = $env:PAGER -split '\s+'
|
||||
if ($moreCommand) {
|
||||
$help | & $moreCommand $moreArgs
|
||||
} elseif ($IsWindows) {
|
||||
$help | more.com
|
||||
} else {
|
||||
$help | less
|
||||
}
|
||||
}
|
||||
";
|
||||
}
|
||||
|
@ -4743,32 +4755,6 @@ end
|
|||
# .Link
|
||||
# https://go.microsoft.com/fwlink/?LinkID=225750
|
||||
# .ExternalHelp System.Management.Automation.dll-help.xml
|
||||
";
|
||||
|
||||
internal const string DefaultMoreFunctionText = @"
|
||||
param([string[]]$paths)
|
||||
# Nano needs to use Unicode, but Windows and Linux need the default
|
||||
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) {
|
||||
[System.Text.Encoding]::Unicode
|
||||
} else {
|
||||
[System.Console]::OutputEncoding
|
||||
}
|
||||
|
||||
# Respect PAGER, use more on Windows, and use less on Linux
|
||||
if (Test-Path env:PAGER) {
|
||||
$pager,$moreArgs = $env:PAGER -split '\s+'
|
||||
$moreCommand = (Get-Command -CommandType Application $pager | Select-Object -First 1).Definition
|
||||
} elseif ($IsWindows) {
|
||||
$moreCommand = (Get-Command -CommandType Application more | Select-Object -First 1).Definition
|
||||
} else {
|
||||
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition
|
||||
}
|
||||
|
||||
if($paths) {
|
||||
foreach ($file in $paths) {
|
||||
Get-Content $file | & $moreCommand $moreArgs
|
||||
}
|
||||
} else { $input | & $moreCommand $moreArgs }
|
||||
";
|
||||
|
||||
internal const string DefaultSetDriveFunctionText = "Set-Location $MyInvocation.MyCommand.Name";
|
||||
|
@ -4780,8 +4766,6 @@ if($paths) {
|
|||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText, isProductCode: true),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", s_tabExpansionFunctionText, isProductCode: true),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText(), isProductCode: true),
|
||||
// Porting note: we keep more because the function acts correctly on Linux
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("more", DefaultMoreFunctionText, isProductCode: true),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText(), isProductCode: true),
|
||||
// Porting note: we remove mkdir on Linux because it is a conflict
|
||||
#if !UNIX
|
||||
|
|
|
@ -529,8 +529,4 @@ Describe "Verify approved aliases list" -Tags "CI" {
|
|||
$result | Write-Host
|
||||
$result | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should have 'more' as a function" {
|
||||
Test-Path Function:more | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ function GetCurrentUserHelpRoot {
|
|||
|
||||
Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') {
|
||||
|
||||
It "Get-Help returns information about the help system." {
|
||||
It "Get-Help returns information about the help system" {
|
||||
|
||||
$help = Get-Help
|
||||
$help.Name | Should -Be "default"
|
||||
|
@ -48,6 +48,20 @@ Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @(
|
|||
}
|
||||
}
|
||||
|
||||
Describe "Validate that the Help function can Run in strict mode" -Tags @('CI') {
|
||||
|
||||
It "Help doesn't fail when strict mode is on" {
|
||||
|
||||
$help = & {
|
||||
# run in nested scope to keep strict mode from affecting other tests
|
||||
Set-StrictMode -Version Latest
|
||||
Help
|
||||
}
|
||||
# the help function renders the help content as text so just verify that there is content
|
||||
$help | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Validate that get-help works for CurrentUserScope" -Tags @('CI') {
|
||||
BeforeAll {
|
||||
$SavedProgressPreference = $ProgressPreference
|
||||
|
|
Loading…
Reference in a new issue