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

Add --no-pager flag #396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

RomanPro100
Copy link

In my tealdeer config I have use_pager set to true, but if there's a case I want it not to be paged, there is no easy way to do this. The only way I found is to change the use_pager option in the config to false.
So I decided it would be nice to have a --no-pager flag that disables paging whether it's enabled in the config or by the --pager flag.
I also added some tests and edited the shell completion scripts, I hope I made everything right.

@niklasmohrin
Copy link
Collaborator

Hey @RomanPro100,

this is definitely a good motivation to implement this flag - thank you for submitting the PR!

I would have thought that clap would be able to generate the --no- version of a flag on its own, but clap-rs/clap#815 is still open. For the time being, I think we should include some more tweaks to the interaction of --[no-]pager, in particular tldr --pager --no-pager and tldr --no-pager --pager should do what the latest argument says. I believe this is done using clap's overrides_with attribute.

A good example on how to do this cleanly is uv:

In our case, we use flag(args.pager, args.no_pager).unwrap_or(config.display.pager), so that the command line parameters always take precedence. All of this "deciding whether or not we spawn a pager" business can be done in main instead of in print_page, because it really is more CLI parsing logic than printing logic.

The tests should cover these cases, i.e. test that CLI takes precedence and that using both --pager and --no-pager together still works as expected. This should optimally include an actual check on whether or not the pager was spawned, for example by using tee tealdeer-pager-log as the pager and then checking for the presence of the tealdeer-pager-log file (we can set the environment variable PAGER when we run the tests).


All of these tasks might be a bit overwhelming, in particular the testing part, so if you have any troubles or questions please reach out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants