-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor: Upgrade to clap v4 #2327
Conversation
Thank you very much! It's probably good to mention that this changes the layout/look of the help text quite dramatically:
|
Signed-off-by: Gábor Lipták <gliptak@gmail.com>
Before doing so, I wanted to double check that this request is with the understanding that |
Not sure I understand correctly. I think that "Use '--help' instead of '-h' to see a more detailed version of the help text." line at the very end of the |
Ohhh, I completely missed that. In that case.. let's hope that others don't miss it as well. And skip those additional explanations. Thank you for the updates! I would like to hear the opinions of the other maintainers before merging this. For reference, the new output looks like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thanks a lot for working on this.
I do however wonder if want clap v4 enough to sacrifice readability of help output (see separate comment).
src/bin/bat/clap_app.rs
Outdated
", | ||
) | ||
// Doesn't play well with `help_template` | ||
.disable_colored_help(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say I feel very strongly about this, but I do think the lack of colors in the help output is quite a significant regression, especially given that bat is all about colored output.
What would be the downsides of bat waiting with upgrading to v4 until v4 supports colors like v3?
From a development point of view it feels very nice to use the latest of everything, but I do think we also need to look at this from a user perspective. Is there any big benefit from a users point of view by upgrading to v4 already now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, which milestone do you consider a blocker:
- Being able to provide a
help_template
that can be stylized like the auto-generated content (the reason Usedisable_colored_help
) - Customizing clap's help styling / theme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is basically that headers stopped being orange and args stopped being yellow. Not sure what it takes to get those colors back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clap v4 moved away from yellow section headers and green args. See the announcement for details. They were replaced by bold and underline.
However, that is not why disable_colored_help
is set. clap v4 also moved the subcommands to the top which is great for most applications where the focus is on the subcommands but that doesn't work well for bat where the subcommand isn't a focus. Bat now has to provide its own help_template
to override the help ordering but this means there are "Arguments", "Options", and "Commands" headers that cannot be styled at this time but other headers are styled. To make things consistent, I've turned off all styling.
So if you want theming from clap (clap-rs/clap#3234), you first need help_template
styling (clap-rs/clap#1433). My initial focus is on help_template
styling. After that I'll focus on theming. The main issue around theming is having a stable API for specifying ansi codes. I've created anstyle for this but need more experience reports / feedback on it before I feel its ready to go 1.0. My hope is the help_tempalate
work will give me experience with it internal to clap to help.
If people want to help towards check, I'd recommend checking out anstyle and providing any feedback on it as a general crate for other crates to have theming support in their API without being tied to termcolor or one of the other crates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To resolve this, I made the following changes:
- I removed the custom template, which re-enables bold/underline styling. Which takes some getting used-to (if you are used to the colorized output), but is IMO also a very reasonable styling alternative that is easy to read.
- I set the
bat cache
subcommand to hidden. This removes the whole "command" section from both-h
and--help
text. - I added a new
.after_help(…)
text that let's users know that there is abat cache
subcommand.
I would really like to integrate the changes here, mostly because I don't want to do this maintenance work later on if we want to upgrade clap for other reasons. I think the "regression" is not too bad. But as I mentioned in an email conversation with @epage as well, I liked the previous "theme" better as well. @Enselic I hope that is okay for you.
@epage: Thank you very much for your patience and this PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me, nice job 👍
(Long term we might be able to bring back the colors)
@@ -77,10 +77,9 @@ default-features = false | |||
features = ["parsing"] | |||
|
|||
[dependencies.clap] | |||
version = "3.2.20" | |||
version = "4.0.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to bump to latest already now (4.0.10 as of now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (Note that the precise version is specified in the lockfile, not here)
This looks great! |
This changes the format of help output
bat
doesn't seem to disable any and it is easier to keep up with new default features likehelp
,usage
, anderror-context
help_template
atm which is required for showingcache
command lasttemplate
clap-rs/clap#1433--help
anymore