Skip to content
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

Merged
merged 13 commits into from May 4, 2018

Conversation

iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Jan 29, 2018

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 } | more
With 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.

@iSazonov
Copy link
Collaborator Author

Please review. I think I did everything I could. Some Help tests failed - looks as breaking change. Also see Get-Process | more.


$process.StartInfo.FileName = 'C:\Windows\system32\more.com'
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardInput = $true
Copy link
Member

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.

Copy link
Collaborator

@BrucePay BrucePay left a 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'
Copy link
Collaborator

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".

@iSazonov
Copy link
Collaborator Author

@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.
If it's acceptable I'll close the PR and make a new.

@daxian-dbw
Copy link
Member

daxian-dbw commented Mar 15, 2018

Removing more function would be a breaking change in that the more function takes multiple file path strings separated by comma ,, while more.com and less don't.

PS:11> more.com F:\test.txt, F:\new.txt
Cannot access file F:\test.txt

Besides, the more function uses a pager if env:PAGER is set. Not sure if this is practically used by anyone though. Apparently this is practically being used :)

@rkeithhill
Copy link
Collaborator

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.

@iSazonov
Copy link
Collaborator Author

We could create the alias at PowerShell startup and keep current platform specific logic - assign more.com on Windows, less on Unix or use env:PAGER.

@daxian-dbw daxian-dbw changed the title [Feature] Add pipeline support in 'more' function [WIP] Add pipeline support in 'more' function Mar 19, 2018
@daxian-dbw
Copy link
Member

Update the PR title to add [WIP].

@daxian-dbw daxian-dbw removed their assignment Mar 19, 2018

$process = [System.Diagnostics.Process]::new()

$process.StartInfo.FileName = 'C:\Windows\system32\more.com'
Copy link
Collaborator

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. ;-)

@iSazonov
Copy link
Collaborator Author

iSazonov commented Mar 30, 2018

@daxian-dbw @SteveL-MSFT
Could you please discuss the breaking change (implement alias for more with default more.com on Windows and less on Unix and given env: PAGER) on PowerShell Committee? It seems to be easier than creating auxiliary process with redirects.

@SteveL-MSFT
Copy link
Member

@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 more function altogether?

@iSazonov
Copy link
Collaborator Author

iSazonov commented Apr 1, 2018

@SteveL-MSFT Yes, we could try to remove more function - but it is a breaking change as @daxian-dbw said above ( more.com F:\test.txt, F:\new.txt ).

@SteveL-MSFT SteveL-MSFT added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Apr 2, 2018
@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee discussed this and agrees we should remove the more function and move the $env:PAGER capability into the help function to preserve that experience. This is a Breaking Change, but it seems that this function has outlived its usefulness and we should respect the pager command the user specified (less vs more, etc...)

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Apr 25, 2018
@iSazonov
Copy link
Collaborator Author

iSazonov commented Apr 26, 2018

Should we implement an alias for more with the $env:PAGER capability?

New-Alias -Name more -Value more.com # for Windows
New-Alias -Name more -Value less     # for Unix

@SteveL-MSFT
Copy link
Member

@iSazonov the discussion in the committee is that more should just be more.com on Windows which seems to be working and not have issues any more based on the comments in the function (we tested against a nanoserver docker container). It seemed wrong that users would have to use more to get $env:PAGER as they should just invoke that specific pager directly. For tools that require automatic paging (like help), it makes sense to respect $env:PAGER (we couldn't think of any other case outside of help function which itself is a separate discussion if we should have that instead of just alias help directly to get-help and support paging...)

@iSazonov iSazonov added the Breaking-Change breaking change that may affect users label Apr 27, 2018
@iSazonov iSazonov changed the title [WIP] Add pipeline support in 'more' function Add pipeline support in 'more' function Apr 27, 2018
@iSazonov iSazonov changed the title Add pipeline support in 'more' function Remove 'more' function and move the $env:PAGER capability into the help function Apr 27, 2018
@iSazonov
Copy link
Collaborator Author

@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
Copy link
Collaborator

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).

Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@iSazonov iSazonov May 1, 2018

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

Copy link
Collaborator

@rkeithhill rkeithhill May 1, 2018

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated my post.

Copy link
Collaborator

@rkeithhill rkeithhill May 1, 2018

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.

Copy link
Collaborator Author

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
Copy link
Member

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.

Copy link
Collaborator Author

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.

@iSazonov
Copy link
Collaborator Author

iSazonov commented May 2, 2018

Add a test for Strict Mode from #6781.

Help
}
# the help function renders the help content as text so just verify that there is content
$help | Should -Not -BeNullOrEmpty $true
Copy link
Member

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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Collaborator

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daxian-dbw daxian-dbw merged commit c1026b3 into PowerShell:master May 4, 2018
@iSazonov
Copy link
Collaborator Author

iSazonov commented May 5, 2018

@rkeithhill Thank you that you caught the lost commits! My mistake was that I did not rebase the old PR.

@iSazonov iSazonov deleted the more-support-pipeline branch May 5, 2018 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking-Change breaking change that may affect users Committee-Reviewed PS-Committee has reviewed this and made a decision
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Help cmdlet fails in PS 6.1.0-preview.1 when StrictMode is enabled
5 participants