mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
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]>
34 lines
943 B
Go
34 lines
943 B
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/vm"
|
|
)
|
|
|
|
// newCodeCmd is devvm code.
|
|
func newCodeCmd(a *app) *cobra.Command {
|
|
var include bool
|
|
cmd := &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 host does, then open its folder in VS Code over Remote-SSH, " +
|
|
"with VS Code's code command.",
|
|
Example: examples(
|
|
"devvm code", "open this folder's VM in VS Code",
|
|
"devvm code --ssh-config", "the same, adding devvm's Include line to ~/.ssh/config without asking",
|
|
),
|
|
Args: noArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
return a.env(func(env *vm.Env) error {
|
|
env.AddInclude = include
|
|
return vm.Launch{Env: env}.Code(cmd.Context())
|
|
}, msg.CodeFailed)
|
|
},
|
|
}
|
|
addSSHConfigFlag(cmd.Flags(), &include)
|
|
addFolderFlags(cmd, a)
|
|
return cmd
|
|
}
|