the-lean-crate / cargo-diet

A cargo-companion to become a 'lean crate' (a member of The Lean Crate Initiative)
https://github.com/the-lean-crate/criner
MIT License
154 stars 3 forks source link

feature: --quiet / --exit-code options #11

Closed cehteh closed 3 weeks ago

cehteh commented 3 weeks ago

for CI tests it would be nice to run 'cargo diet' only as check by having a --exit-code option that returns EXIT_FAILURE when the crate is not already lean (combined or implying -n because you don't want to change the code in a CI).

When one is only interested in this test, but not the actual diff then a --quiet option that suppress all output would be nice.

(Note: one can currently work around that by test "$(cargo diet -n | tail -1)" = "There would be no change." in a shell, but that looks rather brittle.

Byron commented 3 weeks ago

I see where you are coming from.

The currently intended usage is that users run it interactively to review and decide which include rules to accept (or possibly, to reset the rules and see what it proposes).

From there, one can use cargo diet -n --package-size-limit 10KB to monitor if the package grows beyond a certain limit. This would catch accidental additions of files, for example, but will also kick in if the crate is growing naturally.

There currently isn't any other mode where the exit-code is used as it can only make suggestions, and it will also accept existing includes or excludes without doing anything, unless -r is used. Again, in these cases, it needs a user to review what it says.

So for CI usage, the --package-size-limit flag is the only mode that makes sense on CI.

From my experience, even I stopped using it on CI as it failed too often just by me adding code, so right now there isn't really a meaningful way to run it on CI I suppose.

Please do feel free to submit a PR which can add a flag that changes the exit code to non-zero if there is a proposed change. It would solve your problem and should be easy to implement.