-
Notifications
You must be signed in to change notification settings - Fork 1k
Check whether less pager exists before trying to pipe content through it
#6020
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
base: main
Are you sure you want to change the base?
Conversation
|
Noting that, due to Thanksgiving, I will respond to comments on this PR in December. |
|
Thank you for the pull request. I don't think it works to change the default pager since it would be a downgrade and create new issues for the majority of users:
So replacing The standard I think if you wanted to attempt to detect |
less exists on non-Windows systemsless pager exists before trying to pipe content through it
|
@mrsdizzie I've updated this to use the same Unfortunately, I don't have a Windows machine handy to test this change. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Problem
in the corner case where:
wp-cliis running on a non-Windows systemPAGERenvironment variable is not setlessis not installedwp helpcommand:wp-clicommandwp-cli crashes, as documented in #5333
An example of an environment without
lessis many "minimalist" Docker server containers.Changes
lessexists in non-Windows environments when the environment variable$PAGERis not set. Instead, in all environments, invocations ofwp helpwill first check to see iflessexists, and use that, before falling back tomore. The previous behavior was to pipe output throughless -Ron non-Windows systems without first checking iflessexists.Help_Command::pass_through_pager()Alternatives considered
Replacing
less -RwithcatThis would replace a pager with a non-pager, which seems like a feature regression
Replacing
less -Rwithmorein all casesRuled out by @mrsdizzie at #6020 (comment), and removed in b88c438
Accurately checking whether
lessexistsI started a branch with this intent, at benlk@832bb1e , but this approach proved nonviable.
To accurately test whether
lessexists:cmd.exeor Powershell, ascmd.execan usewhereto determine whether a command exists, but Powershell needs to use a different commandcommand -vaccurately determines whether a command exists, we would also need to check for the existence of analias, which is a separate can of wormsproc_close()isn't guaranteed to return the command's exit codeThis seemed like way too much scope creep, introducing too much code, requiring too much testing, for a fallback scenario around displaying a help message.
Testing
The existing tests in https://github.com/wp-cli/wp-cli/blob/main/features/help.feature do not care about whether
moreorlessis used.If additional tests are needed for this change, I'm open to suggestions on what should be tested.
For local testing, on all OS:
echo $PAGERto check what your local shell'sPAGERvariable is. If it is set to any value, including an emptystring, rununset PAGERto unset it.lessto determine whetherlessexists on your system. If it does, runcommand -v less(POSIX) orwhere less(Windows) to determine whether it exists as a binary or as an alias.wpwithout any other commands or optionswp helpis displayed. Iflessexists on your system, it should be paged inless. Iflessdoes not exist, butmoredoes exist in your system, the output should be paged inmore.