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 option to force colorized output #582

Closed
scop opened this issue Nov 18, 2023 · 6 comments · Fixed by #812
Closed

Add option to force colorized output #582

scop opened this issue Nov 18, 2023 · 6 comments · Fixed by #812
Labels
feature request A new lefthook feature description

Comments

@scop
Copy link
Contributor

scop commented Nov 18, 2023

⚡ Summary

An option to force colorized output would be nice. For example when running in GitHub Actions, the output is color capable but lefthook does not currently colorize there.

Value

More color and arguably readability in CI logs when lefthook is run there.

Behavior and configuration changes

Would probably be a good idea to deprecate the existing --no-colors flag and add a new --color={on,off,auto} to replace it.

@scop scop added the feature request A new lefthook feature description label Nov 18, 2023
@mrexox
Copy link
Member

mrexox commented Nov 20, 2023

Hey! There's a config option for that instead – colors. I don't think CLI option would be really useful, since lefthook is supposed to be executed implicitly by git hook.

Do you use lefthook in CI? Could you share your use case please?

@scop
Copy link
Contributor Author

scop commented Nov 20, 2023

I do use (well plan to use) lefthook in CI. Use case is: run exactly same things on developer systems and in CI. Same versions of everything, same config of everything. pre-commit works great for that, but has some other not so great parts that I'd hope lefthook will help fix.

Lefthook does not have builtin help for "same versions of everything" e.g. installing things which pre-commit does have (and that's its killer feature), but I have a hatching project at https://github.com/scop/wrun which will help with that in some cases. Some WIP dogfooding using lefthook at scop/wrun#49 -- this same thing runs both in CI and locally.

@scop
Copy link
Contributor Author

scop commented Nov 20, 2023

Regarding the config option, I guess I could make do with that and set up different config files for CI and local dev, but that's IMO really an antipattern I'd like to avoid having to do by default. In CI we need to invoke lefthook manually, and dropping e.g. --colors=on there would fit in great.

@scop
Copy link
Contributor Author

scop commented Nov 21, 2023

Regarding CI usage, here's pre-commit's related docs: https://pre-commit.com/#usage-in-continuous-integration

In my experience, this use case for pre-commit (and other hook managers) is not at all uncommon, there are lots of repositories e.g. here at GitHub that are set up to run the same hooks locally and in GH Actions.

@scop
Copy link
Contributor Author

scop commented Aug 28, 2024

I found that the indirect termenv dependency supports CLICOLOR_FORCE for this. I'm not sure if it's equal to forcing all color from lefthook, but it's a good start and enough for me for the time being: https://github.com/muesli/termenv?tab=readme-ov-file#usage

Example CI run at https://github.com/scop/wrun/actions/runs/10602871399/job/29385896528 ("Run lefthook pre-commit")

If considering implementing direct support for env based color toggles in lefthook, here are the "strandards" to look into

Currently the said github.com/muesli/termenv and github.com/fatih/color indirect deps have some support for these.

@mrexox
Copy link
Member

mrexox commented Aug 30, 2024

I've addressed this feature request in the PR #812. Please, review it if you have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants