-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
delete-cache --sizes
by show-cache
The `--sizes` flag for `delete-cache` is confusing as it makes the command not actually delete sizes. Deprecate the confusing flag, and add a new command to replace it: `show-cache`.
- Loading branch information
Showing
2 changed files
with
73 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/DataDrake/cli-ng/v2/cmd" | ||
|
||
"github.com/getsolus/solbuild/builder" | ||
"github.com/getsolus/solbuild/builder/source" | ||
"github.com/getsolus/solbuild/cli/log" | ||
) | ||
|
||
func init() { | ||
cmd.Register(&ShowCache) | ||
} | ||
|
||
// ShowCache shows the disk usage of the solbuild cache. | ||
var ShowCache = cmd.Sub{ | ||
Name: "show-cache", | ||
Alias: "sc", | ||
Short: "Show the size of assets stored on disk by solbuild", | ||
Run: ShowCacheRun, | ||
} | ||
|
||
func ShowCacheRun(r *cmd.Root, s *cmd.Sub) { | ||
rFlags := r.Flags.(*GlobalFlags) //nolint:forcetypeassert // guaranteed by callee. | ||
|
||
if rFlags.Debug { | ||
log.Level.Set(slog.LevelDebug) | ||
} | ||
|
||
if rFlags.NoColor { | ||
log.SetUncoloredLogger() | ||
} | ||
|
||
manager, err := builder.NewManager() | ||
if err != nil { | ||
log.Panic("Failed to create new Manager: %e\n", err) | ||
} | ||
|
||
showCacheSizes(manager) | ||
} | ||
|
||
func showCacheSizes(manager *builder.Manager) { | ||
sizeDirs := []string{ | ||
manager.Config.OverlayRootDir, | ||
builder.CacheDirectory, | ||
builder.ObsoleteCcacheDirectory, | ||
builder.ObsoleteSccacheDirectory, | ||
builder.ObsoleteLegacyCcacheDirectory, | ||
builder.ObsoleteLegacySccacheDirectory, | ||
builder.PackageCacheDirectory, | ||
source.SourceDir, | ||
} | ||
|
||
var totalSize int64 | ||
|
||
for _, p := range sizeDirs { | ||
size, err := getDirSize(p) | ||
totalSize += size | ||
|
||
if err != nil { | ||
slog.Warn("Couldn't get directory size", "reason", err) | ||
} | ||
|
||
slog.Info(fmt.Sprintf("Size of '%s' is '%s'", p, humanReadableFormat(float64(size)))) | ||
} | ||
|
||
slog.Info(fmt.Sprintf("Total size: '%s'", humanReadableFormat(float64(totalSize)))) | ||
} |