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

Paginate help output #824

Merged
merged 2 commits into from
Dec 13, 2022

Conversation

chooglen
Copy link
Contributor

@chooglen chooglen commented Dec 1, 2022

It can be useful to paginate the help output (e.g. jj help) for easy reading. This should also support --no-pager for users who prefer not to use pagination, but because of how clap parse help (and others), this requires changing how we parse global args (see the second commit). As a side-benefit, we can now pass --color to jj help.

This is still a WIP because this does not have tests.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have added myself to the contributors in CHANGELOG.md (optional)

src/cli_util.rs Outdated Show resolved Hide resolved
src/cli_util.rs Outdated Show resolved Hide resolved
@chooglen chooglen force-pushed the push-d4cab3ac55474a2f822f3c85ce7a1590 branch 2 times, most recently from 986b816 to 3395683 Compare December 13, 2022 00:08
@chooglen chooglen marked this pull request as ready for review December 13, 2022 00:08
This does not respect "--no-pager", support will be added in the next
commit.
src/cli_util.rs Outdated Show resolved Hide resolved
@chooglen chooglen force-pushed the push-d4cab3ac55474a2f822f3c85ce7a1590 branch from 3395683 to 62e91b9 Compare December 13, 2022 18:12
Clap bails parsing when an "error" is encountered, e.g. a subcommand is missing,
"--help" is passed, or the "help" subcommand is invoked. This means that the
current approach of parsing args does not handle flags like `--no-pager` or
`--color` when an error is encountered.

Fix this by separating early args into their own struct and preprocessing them
using `ignore_errors` (per clap-rs/clap#1880).

The early args are in a new `EarlyArgs` struct because of a known bug where
`ignore_errors` causes default values not to be respected
(clap-rs/clap#4391 specifically calls out bool, but
strings may also be ignored), so when `ignore_errors` is given, the default
values will be missing and parsing will fail unless the right arg types are used
(e.g`. Option`). By parsing only early args (using the new struct) we only need
to adjust `no_pager`, instead of adjusting all args with a default value.
@chooglen chooglen force-pushed the push-d4cab3ac55474a2f822f3c85ce7a1590 branch from 62e91b9 to 986801a Compare December 13, 2022 18:17
@chooglen chooglen merged commit aa2ce88 into jj-vcs:main Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants