aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.61k stars 4.14k forks source link

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

Open mendhak opened 4 years ago

mendhak commented 4 years ago

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

kyleknap commented 4 years ago

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
mendhak commented 4 years ago

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.

thunder-spb commented 4 years ago

Is there any progress on this?

jcatana commented 3 years ago

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?

johnbianchi commented 2 years ago

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?

jimbo8098 commented 2 years ago

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.

Farmbuyer commented 2 years ago

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 commented 1 year ago

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.

ecmonsen commented 1 year ago

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.

bleachbyte commented 3 months ago

This is still continuing to happen; I have the same issue any time I run an aws * help command. Specifying AWS_PAGER has no effect, and --no-cli-pager is not accepted with a help command; I can only get the output to work if I run this as:

PAGER=less aws <whatever> help

...and given that I'd prefer to have control over when I actually have less paginating my output, this isn't the best/most intuitive way to make this work.

graywolf-s1 commented 2 months ago

I think it is absurd this is opened since 2020 when fix is literally 3 changed lines: https://github.com/aws/aws-cli/issues/8891#issuecomment-2324652082 .

I guess I will just have to patch the file locally after every update.

I went through the comments and do not understand why it takes so long to fix it. This should not be about AWS_PAGER at all. The PAGER is already supported for help, but has a bug causing it not being able to handle an empty value. So just quick-fix the bug and debate the rest later, no?

jimbo8098 commented 2 months ago

@graywolf-s1 's fix seems to make sense to me. If the --no-cli-pager option is defined then none should be used regardless of command. If the provided cli pager cannot be found (which his effective PR seems to suggest) then raw output is provided.

However AWS_PAGER should also be obeyed in all situations and - not to get off topic - that's not happening in any situations for Windows unless you define a pager which exists. I completely understand that the presence of this feature is far more important on the bulk user's environment which surely must be Linux/Mac, however many of us are doomed to use Windows too. This comment mentions that this may be changing in .NET 9's handling of empty vars but in the meantime I would expect that an empty string or a NO_CLI_PAGER boolean variable in config would suffice in place of a null variable - which can't be set in Windows.