mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
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]>
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
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"
|
|
)
|
|
|
|
// newNetworkCmd is devvm network [on|off].
|
|
func newNetworkCmd(u *ui.UI) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "network [on|off]",
|
|
Short: "Show or change the network policy of this folder's VM",
|
|
Long: "Show the network policy of this folder's VM: on, off, or unenforced (on, but not confined: " +
|
|
"started outside devvm, or before it was turned on). devvm network on or off changes it from " +
|
|
"the VM's next start: devvm restart. Tokens the VM got while it was off still work once it's on.",
|
|
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
|
|
ValidArgs: []string{"on", "off"},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
withEnv(u, func(env *vm.Env) error {
|
|
n := vm.Net{Env: env}
|
|
if len(args) == 0 {
|
|
return n.Network(cmd.Context(), u.Stdout())
|
|
}
|
|
return n.SetNetwork(cmd.Context(), args[0] == "on")
|
|
}, msg.NetworkFailed)
|
|
return nil
|
|
},
|
|
}
|
|
}
|