holmgr / cargo-sweep

A cargo subcommand for cleaning up unused build files generated by Cargo
MIT License
729 stars 31 forks source link

Show toolchain list only once when the `-i/--installed` flag is provided #86

Closed marcospb19 closed 1 year ago

marcospb19 commented 1 year ago

Here's the output of running cargo sweep -r -i:

[INFO] Using all installed toolchains: ["stable-2022-09-22-x86_64-unknown-linux-gnu", "stable-x86_64-unknown-linux-gnu", "nightly-2022-06-20-x86_64-unknown-linux-gnu", "nightly-2022-08-06-x86_64-unknown-linux-gnu", "nightly-x86_64-unknown-linux-gnu", "1.35.0-x86_64-unknown-linux-gnu", "1.57.0-x86_64-unknown-linux-gnu", "1.58.1-x86_64-unknown-linux-gnu", "1.59.0-x86_64-unknown-linux-gnu", "1.60.0-x86_64-unknown-linux-gnu", "1.61.0-x86_64-unknown-linux-gnu", "1.63.0-x86_64-unknown-linux-gnu", "1.64.0-x86_64-unknown-linux-gnu", "1.65.0-x86_64-unknown-linux-gnu"]
[INFO] Cleaned 0.00 bytes from "/home/marcospb19/PROJECT_1/target"
[INFO] Using all installed toolchains: ["stable-2022-09-22-x86_64-unknown-linux-gnu", "stable-x86_64-unknown-linux-gnu", "nightly-2022-06-20-x86_64-unknown-linux-gnu", "nightly-2022-08-06-x86_64-unknown-linux-gnu", "nightly-x86_64-unknown-linux-gnu", "1.35.0-x86_64-unknown-linux-gnu", "1.57.0-x86_64-unknown-linux-gnu", "1.58.1-x86_64-unknown-linux-gnu", "1.59.0-x86_64-unknown-linux-gnu", "1.60.0-x86_64-unknown-linux-gnu", "1.61.0-x86_64-unknown-linux-gnu", "1.63.0-x86_64-unknown-linux-gnu", "1.64.0-x86_64-unknown-linux-gnu", "1.65.0-x86_64-unknown-linux-gnu"]
[INFO] Cleaned 0.00 bytes from "/home/marcospb19/PROJECT_2/target"
... repeats for a total of 26 projects ...

But here's what the first line looks like in the terminal emulator:

[INFO] Using all installed toolchains: ["stable-2022-09-22-x86_64-unknown-linux-gnu", "stable-x86_64-unknown-linux-gnu", "nightly-2022-06-20-x86_64-unknown-linux-gnu", "nightly-2022-08-06-x86_64-unknown-linux-gnu", "nightly-x86_64-unknown-linux-gnu", "1.35.0-x86_64-unknown-linux-gnu", "1.57.0-x86_64-unknown-linux-gnu", "1.58.1-x86_64-unknown-linux-gnu", "1.59.0-x86_64-unknown-linux-gnu", "1.60.0-x86_64-unknown-linux-gnu", "1.61.0-x86_64-unknown-linux-gnu", "1.63.0-x86_64-unknown-linux-gnu", "1.64.0-x86_64-unknown-linux-gnu", "1.65.0-x86_64-unknown-linux-gnu"]

My home dir has 26 projects, so this gets shown 26 times, making the output unreadable.


IMHO the toolchain list should be shown only once if the -i/--installed flag is provided.

jyn514 commented 1 year ago

Yes, makes sense to me :) I think the way to avoid this is to move this rustup_toolchain_list call: https://github.com/holmgr/cargo-sweep/blob/57a72021ee1b4cd9c27afff004a1d98d21835d62/src/fingerprint.rs#L407-L415 out of the project loop: https://github.com/holmgr/cargo-sweep/blob/42cf364d1615e85bc1b5a0e3a47c2e73ffc076fa/src/main.rs#L250-L252 As a bonus, that will avoid calling rustup once for each project.

marcospb19 commented 1 year ago

Oops, this needs to be reopened, #87 would fix this but I reverted the commits as requested because the PR was too big, so this issue isn't fixed.