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
Remove 'more' function and move the $env:PAGER capability into the help function #6059
Conversation
Please review. I think I did everything I could. Some Help tests failed - looks as breaking change. Also see |
|
||
$process.StartInfo.FileName = 'C:\Windows\system32\more.com' | ||
$process.StartInfo.UseShellExecute = $false | ||
$process.StartInfo.RedirectStandardInput = $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design is apparently not cross-plat. Please revisit the design and make sure it works on all supported platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the more function? I thought @vors fixed the pipeline so that objects would be streamed into executables. Certainly
& { 1..100; sleep -seconds 10; 101..200 } | more
is slow, but
& { 1..100; sleep -seconds 10; 101..200 } | more.com
and
& { 1..100; sleep -seconds 10; 101..200 } | less.exe
show output immediately.
|
||
$process = [System.Diagnostics.Process]::new() | ||
|
||
$process.StartInfo.FileName = 'C:\Windows\system32\more.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should use $ENV:windir instead of hard coding "c:\windows".
@BrucePay Good catch! I think it is best way. Seems we can use an alias for more.com/less. Set-Alias -Name tst -Value "more.com"`
& { 1..100; sleep -seconds 10; 101..200 } | tst show output immediately. |
Removing PS:11> more.com F:\test.txt, F:\new.txt
Cannot access file F:\test.txt Besides, the |
I use Pager on Windows in order to use less. An alias for Pager would be OK as long as I can override it and set it to less. |
We could create the alias at PowerShell startup and keep current platform specific logic - assign |
Update the PR title to add |
|
||
$process = [System.Diagnostics.Process]::new() | ||
|
||
$process.StartInfo.FileName = 'C:\Windows\system32\more.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a path that is only valid on Windows and a binary more.com
that is only valid on Windows? Also, why does the pipeline case ignore the PAGER utility specified in the $env:PAGER? I always use less
, even on Windows. I need to be able specify less
on Windows. If I was forced to use more.com
I'd go batsh!t in short order. ;-)
@daxian-dbw @SteveL-MSFT |
@iSazonov can you be more specific on what you think needs to be discussed by @PowerShell/powershell-committee? Is it whether we should remove the |
@SteveL-MSFT Yes, we could try to remove |
@PowerShell/powershell-committee discussed this and agrees we should remove the |
Should we implement an alias for New-Alias -Name more -Value more.com # for Windows
New-Alias -Name more -Value less # for Unix |
@iSazonov the discussion in the committee is that |
This reverts commit e6c11fd.
dd46181
to
b25acd9
Compare
@daxian-dbw @SteveL-MSFT The PR is ready for review. |
$help | more | ||
# Respect PAGER, use more on Windows, and use less on Linux | ||
if (Test-Path env:PAGER) { | ||
$moreCommand = (Get-Command -CommandType Application $env:PAGER | Select-Object -First 1).Definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lose the ability to specify arguments to the pager utility - $pager,$moreArgs = $env:PAGER -split '\s+'
. That doesn't bother me personally but presumably somebody added these for a reason (an issue I suspect).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was explicitly to fix #6142
Should just use the same code as from https://github.com/PowerShell/PowerShell/pull/6144/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder!
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add tests to exclude such regression?
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition | ||
} | ||
|
||
$help | & $moreCommand $moreArgs $moreArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC someone (@BrucePay) had initialized $moreArgs
to an empty string above the preceding if/else statements to prevent a strict mode failure ($moreArgs not being defined when $env:PAGER is not defined).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
$pager,$moreArgs = $env:PAGER -split '\s+'
if ($pager != $null) {
$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
}
$help | & $moreCommand $moreArgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have $moreArgs
listed twice after the invocation of $moreCommand
. There should only be one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated my post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, watch out for $pager != $null
. That should be -ne
. That said, this line:
$pager,$moreArgs = $env:PAGER -split '\s+'
Will assign an empty string, not $null
, to $pager when $env:PAGER
is not defined. So I think the test should be simply: if ($pager)
. And ideally, if get-command
can't find the app referred to by $env:PAGER, it should revert back to the default for the OS. Otherwise, you're left with a $null in $moreCommand and help | & $null
will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing Get-Command -CommandType Application
? We get the same error for badapp
, & badapp
and Get-Command -CommandType Application badapp
.
$pager,$moreArgs = $env:PAGER -split '\s+'
if ($pager) {
$moreCommand = $pager
} elseif ($IsWindows) {
$moreCommand = "more.exe"
} else {
$moreCommand = "less"
}
$help | & $moreCommand $moreArgs
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition | ||
} | ||
|
||
$help | & $moreCommand $moreArgs $moreArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have $moreArgs listed twice after the invocation of $moreCommand. There should only be one.
Not only in your post, that's also the case in your code change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do rebase but I wanted to keep the commit history. As a result lost the essence.
The code was refactored.
Add a test for Strict Mode from #6781. |
fbc9dc2
to
31ab358
Compare
Help | ||
} | ||
# the help function renders the help content as text so just verify that there is content | ||
$help | Should -Not -BeNullOrEmpty $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$true
is not needed. See #6781 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@rkeithhill Thank you that you caught the lost commits! My mistake was that I did not rebase the old PR. |
PR Summary
Address #1267.
Fix #6497.
Based on PowerShell Committee conclusion (see below) and PR Native pipe #2450 we remove
more
function. Now users is free to use preffered pager directly or create a custom alias.To keep current
help
function behavior we move a pager capability (with $env:PAGER support) to the function.Before the change we had to wait 10 seconds before we could see the script output:& { 1..100; sleep -seconds 10; 101..200 } | moreWith this change we will see the output without delay.I have no idea how to test this.PR Checklist
Note: Please mark anything not applicable to this PR
NA
.[feature]
if the change is significant or affects feature testsWIP:
to the beginning of the title and remove the prefix when the PR is ready.