mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 14:33:17 -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]>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/w3cj/devvm/internal/gitprotect"
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/ui"
|
|
"github.com/w3cj/devvm/internal/vm"
|
|
)
|
|
|
|
// newGitProtectCmd is devvm git-protect [on|strict|off].
|
|
func newGitProtectCmd(u *ui.UI) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "git-protect [on|strict|off]",
|
|
Short: "Show or change .git protection for this folder's VM",
|
|
Long: "Show whether this folder's VM can change the parts of .git that run code on this machine: " +
|
|
"on (the default on macOS: hooks and config locked), strict (on, and host git status and diff " +
|
|
"stay out of submodules), off, or clone for a --clone VM. devvm git-protect on, strict or off " +
|
|
"changes it while the VM is stopped; on and strict lock .git as it is now. Locks need macOS.",
|
|
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
|
|
ValidArgs: gitprotect.Modes,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
withEnv(u, func(env *vm.Env) error {
|
|
s := vm.Settings{Env: env}
|
|
if len(args) == 0 {
|
|
return s.GitProtect(cmd.Context(), u.Stdout())
|
|
}
|
|
return s.SetGitProtect(cmd.Context(), args[0])
|
|
}, msg.GitProtectFailed)
|
|
return nil
|
|
},
|
|
}
|
|
}
|