mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-06 09:20:34 -10:00
devvm space [--json] lists each kind of thing devvm keeps, on every backend, with its count, size (allocated blocks, as du), whether devvm makes it again (remade, only copy, log, state, leftover), what devvm gc frees of it now and what frees the rest, then a total: VMs and images per backend, shared tool builds per backend and C library, exports, network and run logs, devvm's own mise, the copies of devvm's files, the leftover state of VMs their backend no longer has, and the rest of devvm's state. The backends' own caches come apart and outside the total: Lima's download cache, smolvm's caches on macOS (pack disks, image disks, archives, registry; never its machines' folders) and Docker's labelled volumes that aren't one VM's own. backend.UsageReporter (optional): Lima, smolvm and Docker say what their VMs and caches take. Each backend gets 30 s; one that doesn't answer is named when a VM's state uses it (space_backend_unknown), and its VMs are never counted as leftovers. Each tool build now leaves <image>.target beside it (libc, format), so listings tell a Lima, smolvm and Docker build of a version apart; tools.Listed has Target, from the record or the target it's current for; Share.Delete deletes the record too. Messages: reading_space, space_failed, space_backend_unknown, space_caches_note. Stubs: docker volume ls; smolvm machine ls fails with smolvm-ls-fails. Docs: the What devvm keeps page leads with devvm space; commands table; images' Cleaning up; CLI reference. Review: space runs only listings (limactl list, smolvm machine ls and data-dir, docker info, container ls/inspect --size, system df, volume ls), each bounded by ctx with a timeout; the txtar checks no call creates, deletes, starts, stops or edits. Backend caches aren't in the total. Sizes checked against du on the e2e sandbox data and the user's caches (Lima 9.1G, smolvm pack disks 20G, both match du -sh). APFS clones count for both, as the page says. Co-Authored-By: Claude Opus 5.5 <[email protected]>
69 lines
3.1 KiB
Go
69 lines
3.1 KiB
Go
// Package cli holds devvm's commands.
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/ui"
|
|
)
|
|
|
|
// NewRoot returns the devvm command with every subcommand registered, each
|
|
// printing and asking through u. devvm itself is up: a shell in this
|
|
// folder's VM.
|
|
func NewRoot(u *ui.UI) *cobra.Command {
|
|
g := new(globals)
|
|
uf := new(upFlags)
|
|
root := &cobra.Command{
|
|
Use: "devvm [IMAGE]",
|
|
Short: "Open a shell in this folder's VM, creating it first",
|
|
Long: "Open a shell in this folder's VM, at the same path, creating the VM first. A new VM " +
|
|
"gets IMAGE (base, layers such as docker or your own, and the shared tools joined with +: " +
|
|
"node+python+docker+claude), " +
|
|
"else the toolchains (and the nix layer) the folder's files call for, with any agents IMAGE names on top, built " +
|
|
"if it isn't. Only the folder is mounted, read-write, with the shared tools read-only, and " +
|
|
"its .git hooks and config are locked against changes from the VM (macOS); with --clone, " +
|
|
"nothing is mounted but the shared tools, and the VM gets its own clone of the repo. A new VM also gets " +
|
|
"what the folder's devcontainer.json says it can, unless --no-devcontainer. A VM that exists " +
|
|
"is started if it's stopped and opened as it is; an IMAGE that names what it lacks adds that " +
|
|
"in place, after asking. In a folder without a VM of its own, inside one that has a VM, devvm " +
|
|
"asks whether to open that VM in this folder instead of creating one, and opens it without " +
|
|
"asking when there's no terminal. --here and --clone create the new VM without asking.",
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
Args: cobra.MaximumNArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return up(cmd.Context(), u, g, uf, args)
|
|
},
|
|
}
|
|
root.SetOut(u.Stdout())
|
|
addGlobals(root, g)
|
|
addUpFlags(root, uf)
|
|
addVersion(root)
|
|
root.AddCommand(newBuildCmd(u, g), newRebuildCmd(u, g), newImagesCmd(u, g), newGCCmd(u, g), newSpaceCmd(u, g), newLayerCmd(u), newSetupCmd(u), newMsgCmd(u),
|
|
newRestartCmd(u, g), newStopCmd(u), newRemoveCmd(u, g), newUpdateCmd(u, g), newAdoptCmd(u), newExportCmd(u), newRmCmd(u), newLsCmd(u), newLogCmd(u), newPolicyCmd(u), newNetworkCmd(u), newSSHCmd(u), newCodeCmd(u), newDesktopCmd(u), newSSHAgentCmd(u), newGitProtectCmd(u), newPortsCmd(u), newSizeCmd(u), newDoctorCmd(u, g), newLimactlCmd(u), newQEMUCmd(u), newProxyCmd(u), newLimaPortsCmd(u), newSmolvmPortsCmd(u), newDockerPortsCmd(u), newDockerConnectCmd(u), newRefreshToolsCmd(u), newSecretCmd(u),
|
|
newAuthCmd(u), newVersionCmd(u), newCompletionCmd(u))
|
|
addCompletions(root, u)
|
|
return root
|
|
}
|
|
|
|
// Execute runs devvm with args on u and returns its exit code. A command's
|
|
// error is printed like Warn: a message as it is, the command line
|
|
// parser's own ("unknown command") in usage_error.
|
|
func Execute(ctx context.Context, u *ui.UI, args []string) int {
|
|
root := NewRoot(u)
|
|
root.SetArgs(args)
|
|
if err := root.ExecuteContext(ctx); err != nil {
|
|
m, ok := errors.AsType[msg.M](err)
|
|
if !ok {
|
|
m = msg.UsageError(err.Error())
|
|
}
|
|
u.Warn(m)
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|