toolclean

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package toolclean discovers developer tools present on the machine and runs each tool's own cache-cleanup command (e.g. `uv cache prune`, `pnpm store prune`, `cargo clean`). Letting a tool prune itself is safer than `rm -rf`: it removes only what it can rebuild and keeps the tool's bookkeeping consistent. This mirrors the show_tool_cleanups step of the reference script.

It also discovers Rust project build directories under common project roots (overridable via CLEANX_PROJECT_DIRS) and offers a per-project `cargo clean`, since target/ dirs are routinely the largest reclaimable space on a dev box.

Command execution and sizing are injected (CmdRunner / SizeFunc) so discovery, selection, and freed-space accounting are unit-tested without touching the system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjectRoots

func ProjectRoots(home string) []string

ProjectRoots returns the directories searched for Rust build dirs. It honours a colon-separated CLEANX_PROJECT_DIRS override; otherwise it probes common conventions (non-existent ones are skipped during discovery).

Types

type Cleanup

type Cleanup struct {
	Label   string
	Name    string   // command binary
	Args    []string // command arguments
	SizeDir string   // directory measured for size + freed accounting ("" if none)
	SizeKB  int64    // current size of SizeDir, filled by Available
}

Cleanup is one offered tool cleanup: a label, the command to run, and the directory whose size is measured before/after to report space reclaimed.

func Available

func Available(home string, sizeKB SizeFunc) []Cleanup

Available returns the tool cleanups whose binaries exist, each sized via sizeKB, plus per-project `cargo clean` entries discovered under the project roots (only when the cargo binary is present).

func (Cleanup) Command

func (c Cleanup) Command() string

Command returns the human-readable command string shown to the user before they select a cleanup (e.g. "brew cleanup -s --prune=all").

func (Cleanup) Run

func (c Cleanup) Run(sizeKB SizeFunc, runner CmdRunner) (freedKB int64, runErr error)

Run executes the cleanup via runner and returns the kilobytes reclaimed, measured as the drop in SizeDir's size (tools prune internally, so the listed size is not necessarily what is freed). A cleanup with no SizeDir reports 0 freed. runErr is the command's error, if any.

type CmdRunner

type CmdRunner func(name string, args ...string) error

CmdRunner executes a command, returning an error on non-zero exit. The production runner streams stdout/stderr to the user's terminal.

type SizeFunc

type SizeFunc func(path string) int64

SizeFunc returns the size of a path in kilobytes (du -sk semantics).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL