aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

[v2] Unable to prevent aws help output from going to a pager (AWS_PAGER, PAGER aren't respected)

Open mendhak opened this issue 4 years ago • 7 comments

The aws cli now sends its output to a pager. The cli also sends its help output to a pager which we've been finding to be disruptive and unhelpful; the help output disappears after exiting the pager (press q). This is difficult to work with when porting scripts and when remoted in.

Problem

According to the pull request that added this feature, we should be able to set AWS_PAGER="" or PAGER="" and the CLI should not send the output to a pager. This is not working for us. Try:

PAGER=""  aws ec2 help

results in

list index out of range

AWS_PAGER=""  aws ec2 help

results in the help output shown in a pager anyway.

Expected

The environment variables AWS_PAGER="" or PAGER="" should be respected, setting those to "" should disable the help output pager. Alternatively, the aws cli v2 output and help output should not go to a pager; make the paging feature opt-in rather than opt-out.

Versions

aws-cli/2.0.0 Python/3.7.3 Linux/5.3.0-29-generic botocore/2.0.0dev4

Ubuntu 18.04

mendhak avatar Feb 18 '20 07:02 mendhak

In the pull request, it was intended that the pagers only affected command output. That being said, I'm not opposed to adding the option to control the pager functionality for the help command as well. The only thing thing I'm hesitant about is making the help pager rely on the same variables as the output pager (e.g. AWS_PAGER) as it may result in unexpected behavior for users that upgrade and not expecting the AWS_PAGER variable to affect their help output. I think if we add it, it would likely be through another environment and config variables (e.g. AWS_HELP_PAGER). This option would also give more granularity over how to page different types of outputs as well.

In the meantime if you want to have the help output be printed directly to stdout, you can use a pipe (i.e. to something like cat) and the CLI will not send it to the pager.

$ aws ec2 help | cat

kyleknap avatar Feb 18 '20 21:02 kyleknap

Thanks, any environment-variable means to disable it should be fine; I can work with the cat method for now though explaining it to many devs isn't a simple task so I am eager for a fix to this.

I should add: I'm also one of the users upgrading and I did expect AWS_PAGER to disable all the paging, not just command output. The breaking changes doc doesn't make a distinction:

You can completely disable all use of an external paging program by setting the variable to an empty string as shown in the following examples.

so it makes sense at least to me that all pager output is disabled rather than the user having to understand the distinction.

mendhak avatar Feb 20 '20 08:02 mendhak

Is there any progress on this?

thunder-spb avatar Aug 18 '20 10:08 thunder-spb

Not having a way to change this is one of those mildly annoying things that becomes infuriating because of how simple it should be. You read the docs and try to disable it, but nowhere does it state it doesn't apply to help output. Any updates?

jcatana avatar Oct 14 '21 04:10 jcatana

Ran into this one today too. Because VSCode's "Terminal" happily gives you a pager even when PAGER is unset, I had to set PAGER="" in my environment a week ago or so. was trying some aws cli commands and every try for help gave

$ aws help
 list index out of range

helpful, isn't it? All googling failed me and I searched here and found this issue.

aws cli, just like VSCode's Terminal, seems to feel if there is no PAGER env var, then we want a pager by default! well, ok, but how do I tell it to NOT do a pager?

johnbianchi avatar Mar 16 '22 21:03 johnbianchi

Windows

In Windows 10 Pro 21H2, I notice that neither PAGER nor AWS_PAGER are respected as I would expect in that they still produce paginated output or provide an error.

Powershell 7.2.5

Both of the following commands result in paginated output.

$AWS_PAGER=""; $PAGER=""; aws secretsmanager help
$AWS_PAGER=""; $PAGER=""; aws ec2 describe-instances

The following works as expected and does not produce paginated output:

aws ec2 describe-instances --no-cli-pager

Of course, this flag isn't accepted on help output so there's no workaround there.

Command Prompt

I tried the commands below in Command Prompt and found the following:

C:\Users\JimSpeir>aws ec2 help
#Paginated output
C:\Users\JimSpeir>set PAGER=""

C:\Users\JimSpeir>set AWS_PAGER=""

C:\Users\JimSpeir>aws ec2 help
'""' is not recognized as an internal or external command,
operable program or batch file.

Which I think shows that the environment variables are being read and used to an extent since it looks like awscli is trying to spawn "" as a program. It should instead be producing non-paginated output.

Linux

I've never had any issues on Ubuntu 22.04 with the default build not producing paginated output. I've found WSL Ubuntu containers are the same as stock Ubuntu which gives me something of an out if it really bothers me. But it kind of sucks that I have to google the command to get the manpage instead of just being able to view it.

jimbo8098 avatar Jul 13 '22 08:07 jimbo8098

I think if we add it, it would likely be through another environment and config variables (e.g. AWS_HELP_PAGER). This option would also give more granularity over how to page different types of outputs as well.

This would provide not only the least-surprising, least-disruptive path forward, but also give users maximal control.

Right now I'm using cli_pager = in the config file to turn off pagination by default, but then using PAGER=less aws <whatever> help to have useful searching / backscrolling / etc when reading a help topic. (This works even though the documentation says cli_pager takes precedence, because help is apparently different.)

We could also use aws <whatever> help | less but that's slightly less convenient, and the total goal of all computer science is to minimize human inconvenience.

Farmbuyer avatar Aug 17 '22 14:08 Farmbuyer

but then using PAGER=less aws <whatever> help to have useful searching / backscrolling / etc when reading a help topic.

I should add that (at least as I write this with aws-cli 2.11.18), this only works with PAGER. Setting AWS_PAGER in this way is ignored, since cli_pager does take precedence over environment variables in that case.

Farmbuyer avatar May 10 '23 17:05 Farmbuyer

I'm having the opposite problem, where aws help is NEVER paged, but I would like it to be. I'm on mac OS Sonoma (Apple Silicon), using aws on zsh and bash. The proposed solution of an AWS_HELP_PAGER env var would be acceptable.

ecmonsen avatar Nov 29 '23 00:11 ecmonsen