Files
devvm/internal/cli/code.go
T
w3cjandClaude Opus 5.5 1e4c772cc5 refactor(vm): split Env's commands into types by group
Env holds the shared dependencies NewEnv sets and the helpers every
group uses: finding the folder's VM, starting it, applying its size and
ports, the image builder and the ssh config. The commands are on types
that embed *Env:

- Launch: up, restart, remove, update, ssh and code; a new VM
  (up.go), an existing one (existing.go), ssh.go, agents' mounts
- Lifecycle: stop, adopt, rm and export (lifecycle.go)
- Settings: .git protection (settings.go), size (size.go), ports
  (ports.go), SSH agent forwarding (sshagent.go)
- Net: network policy, its log and allowlist (network.go), secrets
  (secret.go)
- clones (clone.go) and syncer (sync.go), used by the others

env.go holds Env, UI, NewEnv and the shared helpers. cli's commands
call the group they need, e.g. vm.Launch{Env: env}.Up. Tests follow
their code: env_test.go holds the shared helpers, with up_test.go,
lifecycle_test.go, network_test.go and ports_test.go beside them.
The most methods on one type is 24 (Launch).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 16:44:53 -06:00

26 lines
828 B
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/w3cj/devvm/internal/msg"
"github.com/w3cj/devvm/internal/ui"
"github.com/w3cj/devvm/internal/vm"
)
// newCodeCmd is devvm code.
func newCodeCmd(u *ui.UI) *cobra.Command {
return &cobra.Command{
Use: "code",
Short: "Open this folder's VM in VS Code over Remote-SSH",
Long: "Get this folder's VM ready as devvm ssh does, then open its folder in VS Code over Remote-SSH, " +
"with VS Code's code command. The VM's VS Code settings turn off forwarding its ports to this " +
"machine and answering git's sign-in prompts with your GitHub sign-in.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
withEnv(u, func(env *vm.Env) error { return vm.Launch{Env: env}.Code(cmd.Context()) }, msg.CodeFailed)
return nil
},
}
}