Files
devvm/internal/cli/proxy.go
T
w3cjandClaude Opus 5.5 4bbd35a24b refactor(ui): make the UI an instance only cli holds
internal/ui has no package state: ui.UI holds the streams, terminal
flags, run log, status line, cleanup stack and interrupt flag, and its
functions are methods. ui.Main makes the run's UI on devvm's own
streams, owns signals, recovers Die and runs the cleanups; ui.New makes
one on other streams. cmd/devvm passes it to cli.Execute, and every cli
command gets it through its constructor.

Only cmd/devvm and internal/cli import internal/ui (a depguard rule).
Each other package defines the small UI interface it needs, which its
constructor takes, filling fields tests set:
- gitprotect.New, secrets.NewStore, from.NewLookup: a warn func
- ubuntu.New: LoggedCmd, Note
- netpolicy.NewProxy: Note, Warn, Ask, Confirm, StdinIsTerminal; its
  log lines drop control characters themselves (oneLine)
- sshagent.New: Info, Note, Warn, LogWriter
- tools.New: Info, Warn, LogNote, Status, LoggedCmd, AddCleanup
- lima.New, smolvm.New: Info, Warn, LoggedCmd (their Runner's Run),
  WithSteps, AddCleanup, Interrupted; lima LogNote and ubuntu's too
- backends.Registry: lima's and smolvm's
- vm.NewEnv: all of the above, Say, Stdout, Stderr; Env has Stdout,
  LogNote, LogWriter, LoggedCmd, AddCleanup, Interrupted fields
- build.Builder: Terminal and LogNote fields
- sshconfig.New: its caller sets what it prints and asks

ui's tests build their own UI over buffers and run in parallel; other
packages' tests use small fakes; cli's unit tests a UI over buffers.

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

37 lines
1.1 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/w3cj/devvm/internal/msg"
"github.com/w3cj/devvm/internal/proxy"
"github.com/w3cj/devvm/internal/secrets"
"github.com/w3cj/devvm/internal/ui"
)
// newProxyCmd is devvm _proxy: one VM's network policy proxy, and the
// one-shot modes devvm runs it in (-init-ca, -login, -redact). Hidden: it's
// not for users. Its flags are the proxy's own (one dash or two), parsed by
// proxy.Main; its event log and log lines are data, written to devvm's
// stdout and stderr.
func newProxyCmd(u *ui.UI) *cobra.Command {
return &cobra.Command{
Use: "_proxy [flags]",
Short: "Run a VM's network policy proxy",
Hidden: true,
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := proxy.Main(args, proxy.IO{
Stdin: cmd.InOrStdin(),
Stdout: u.Stdout(),
Stderr: u.Stderr(),
Kept: func(agent string, names []string) { secrets.LoginKept(u.Warn, agent, names) },
})
if err != nil {
u.Die(msg.ProxyFailed(err.Error()).Because(err))
}
return nil
},
}
}