mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
devvm takes no IMAGE word any more than any other: in a terminal a new VM's toolchains, coding agents and layers are checked in one picker, under three headings, before the network-policy question; --tools, --agents and --layers (each an exact list, or none) skip it, and a part left out takes its default: the detected toolchains, devvm setup's agents, no layers (a devcontainer.json's features still count). Without a terminal, or with --no-input, the VM gets the defaults and new_vm_gets says so in one line. devvm setup --agents (and its first-run question) chooses new VMs' agents. devvm tools in a terminal opens the same picker for the VM, its layers fixed, and turns the changes into tools add and rm. An image is base and layers only: tools are the VM's tool_names state key. build, rebuild and images rm refuse a shared tool (tool_not_layer), and devvm build builds no tool images. devvm ls gains a TOOLS column and --json tools. gc's --tools is --tool-images, so --tools has one meaning. Gone: image.Reserved, checkWord's image half (devvm WORD is no_command or no_command_like, did-you-mean over commands, msg.Closest), the lacks path in internal/vm/existing.go, and the messages vm_lacks_tools, vm_lacks_layer, layer_is_command, layer_name_command, no_image_for, no_command_or_image*, tools_not_images, tools_not_images_rm, detected, vm_is_now (vm_tools_now), secret_with_image (secret_with_claude). New: ui.Pick takes headed sections with fixed rows, ui.CanPick, vm.PickPart/PickRow/AgentsChoice/CheckPart (internal/vm/parts.go), state.KeyToolNames, state.ReadAgents/WriteAgents, paths.Dirs.Agents, project.DetectFiles. Image keys are unchanged in form: images never held tools; docker.sh's and nix.sh's comments changed, so those layers rebuild. Docs: the home page's quick start steps, diagram (sandbox.svg), cards and FAQ; README; getting started; using (images' What a new VM gets, coding agents' Running an agent, settings' agents); internals; contributing; the cli skill; AGENTS.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"slices"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
|
|
"github.com/w3cj/devvm/internal/from"
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/ui"
|
|
)
|
|
|
|
// addBackendFlag adds --backend, the backend a command uses: a new VM's,
|
|
// or the one it builds, deletes or checks on.
|
|
func addBackendFlag(f *pflag.FlagSet, p *string) {
|
|
f.StringVar(p, "backend", "", "the backend `NAME` to use (default: devvm setup's, else lima)")
|
|
}
|
|
|
|
// addBackendFilterFlag adds --backend as a filter: a command that acts on
|
|
// every backend acts on that one alone.
|
|
func addBackendFilterFlag(f *pflag.FlagSet, p *string) {
|
|
f.StringVar(p, "backend", "", "act only on the backend `NAME` (default: every backend)")
|
|
}
|
|
|
|
// addFromFlag adds --from, the container image a base starts from.
|
|
func addFromFlag(f *pflag.FlagSet, p *string) {
|
|
f.StringVar(p, "from", "", "the container `IMAGE` base starts from, such as node:24, instead of Ubuntu's cloud image (default: $DEVVM_FROM)")
|
|
}
|
|
|
|
// addAgentsFlag adds --agents, a list of coding agents: a new VM's, or
|
|
// new VMs' default with devvm setup. usage says whose.
|
|
func addAgentsFlag(f *pflag.FlagSet, p *string, usage string) {
|
|
f.StringVar(p, "agents", "", usage)
|
|
}
|
|
|
|
// addForceFlag adds -f/--force, which only skips a confirmation.
|
|
func addForceFlag(f *pflag.FlagSet, p *bool) {
|
|
f.BoolVarP(p, "force", "f", false, "don't ask to confirm, which devvm needs without a terminal")
|
|
}
|
|
|
|
// addSSHConfigFlag adds --ssh-config, which answers the question whether
|
|
// to add devvm's Include line to ~/.ssh/config.
|
|
func addSSHConfigFlag(f *pflag.FlagSet, p *bool) {
|
|
f.BoolVar(p, "ssh-config", false, "add devvm's Include line to ~/.ssh/config without asking")
|
|
}
|
|
|
|
// confirmed is whether a destructive command (command, as typed) goes
|
|
// ahead: with --force without asking; in a terminal, when ask says yes;
|
|
// without one, never, refused with force_needed.
|
|
func confirmed(u *ui.UI, force bool, command string, ask func() bool) (bool, error) {
|
|
switch {
|
|
case force:
|
|
return true, nil
|
|
case !u.StdinIsTerminal():
|
|
return false, msg.ForceNeeded(command)
|
|
}
|
|
return ask(), nil
|
|
}
|
|
|
|
// fromRef is --from as given, else its default from the environment.
|
|
func fromRef(flag string) string {
|
|
if flag != "" {
|
|
return flag
|
|
}
|
|
return os.Getenv(from.Env)
|
|
}
|
|
|
|
// noBlanks refuses a flag given an empty value, and an empty argument: no
|
|
// flag or argument takes a blank to mean none or its default. A command
|
|
// that passes its arguments on as they are (limactl) is left alone.
|
|
func noBlanks(cmd *cobra.Command, args []string) error {
|
|
if cmd.DisableFlagParsing {
|
|
return nil
|
|
}
|
|
var err error
|
|
cmd.Flags().Visit(func(f *pflag.Flag) {
|
|
if err == nil && f.Value.Type() == "string" && f.Value.String() == "" {
|
|
err = msg.FlagBlank(f.Name)
|
|
}
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if slices.Contains(args, "") {
|
|
return msg.ArgBlank(cmd.CommandPath())
|
|
}
|
|
return nil
|
|
}
|