Files
devvm/internal/cli/gitprotect.go
T
w3cjandClaude Opus 5.5 ca8a91305b fix(ui): one failure path, and an interrupt's cleanups wait for the command
Commands fail by returning: RunE returns the error, as failed(err, what)
when it may not be a message (replacing fail and the direct Die calls in
cli), and a.env returns its failure. checkLayout returns its error from the
root's PersistentPreRunE. execute alone prints a failure (showFailure): a
backend.LoggedError with the run log's end (ui.ErrorLogged, which replaces
DieLogged), a message as it is, else what failed or output_failed, with a
corrupt file's message as names mode shows it. Exit codes stay 0, 1, 2, 130.

Die is now the UI's own die, for where no command can return: a question
without an answer, a run log that can't be opened. Error prints nothing once
the run is interrupted.

After INT, TERM or HUP, Main waited only for the logged command and then ran
the cleanups while the command's own code still ran. It now also waits for
the command to return, up to returnGrace (2 s), when there are cleanups to
run; a run without cleanups ends at once, so the proxy and the other
background processes still stop as soon as they are told to. A start's
undoStart stays registered once interrupted (interruptCleanup), as the
cleanups now run after the start returned.

Tests: TestSignalsWaitForTheCommandBeforeTheCleanups (failed on the old
ordering), TestSignalsWaitForAStuckCommandAWhile,
TestSignalsWithoutCleanupsEndAtOnce, TestExecuteShowsEachFailure;
DieLogged's tests are ErrorLogged's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 10:42:20 -07:00

47 lines
1.5 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/vm"
)
// newGitProtectCmd is devvm git-protect [on|strict|off].
func newGitProtectCmd(a *app) *cobra.Command {
var asJSON bool
cmd := &cobra.Command{
Use: "git-protect [on|strict|off]",
Short: "Show or change .git protection for this folder's VM",
Long: "Show this folder's VM's .git protection, which locks the git hooks and config that run code on this machine, " +
"as on, strict, off, or clone for a --clone VM. " +
"devvm git-protect on, strict or off changes it at once on a stopped VM, and on a running one when it next stops, so in a terminal devvm offers to restart it now.",
Example: examples(
"devvm git-protect", "show the VM's .git protection",
"devvm git-protect off", "unlock .git, once the VM is stopped",
"devvm git-protect on", "lock .git again as it is then",
),
Args: showsOnly(maxArgs(1)),
ValidArgs: gitprotect.Modes,
RunE: func(cmd *cobra.Command, args []string) error {
var mode string
err := a.env(func(env *vm.Env) error {
s := vm.Settings{Env: env}
if len(args) == 1 {
return s.SetGitProtect(cmd.Context(), args[0])
}
var err error
mode, err = s.GitProtect(cmd.Context())
return err
}, msg.GitProtectFailed)
if err != nil || len(args) == 1 {
return err
}
return printValue(a.u, asJSON, "mode", mode)
},
}
jsonFlag(cmd, &asJSON)
return addFolderFlags(cmd, a)
}