Files
Reims-Go/internal/cli/window_args.go
T
Nwflower 59aaf36eb5 refactor(app): key VM runtime state by VMRef
Qualify transitions, pending changes, reboot watchers, disk/process caches, typing queues, thumbnail locks, and VM log sources so same-named VMs do not share mutable state.

Read driver-qualified transition keys in the frontend and add --start-driver to CLI/window handoff. Legacy window start rejects other drivers explicitly until lifecycle routing lands.
2026-11-30 07:51:10 -07:00

100 lines
3.1 KiB
Go

package cli
import (
"strconv"
"strings"
)
// The desktop window's own flags. `vm start` launches the window with them
// (or sends them to a window already running), so they are the whole
// protocol between command-line mode and the window. Each flag is one
// argument (`--name=value`) so a stray value is never taken for a command.
const (
flagBackground = "--background"
flagSafeMode = "--safe-mode"
flagStartVM = "--start-vm="
flagStartDriver = "--start-driver="
flagStartResult = "--start-result="
flagWaitPID = "--wait-pid="
)
// WindowArgs is what the desktop window was asked to do at launch, or by a
// later `reims-go` run handing work to it.
type WindowArgs struct {
// Background keeps the window hidden; Reims-Go lives in the tray.
Background bool
// SafeMode skips all third-party plugins and reverts to the built-in theme (§9).
SafeMode bool
// StartVM is a VM to start as the GUI's StartVM would (Guest Tools and
// the Win10 cold-reboot watcher included).
StartVM string
// StartDriver identifies the VM's owning driver when names are ambiguous.
StartDriver string
// StartResult is a file the window writes a StartResult to once StartVM
// has returned, so the command that asked can report it.
StartResult string
// WaitPID is a Reims-Go process that is quitting after installing an
// update: the new window waits for it to exit before taking the
// single-instance lock, which it would otherwise hand straight back to it.
WaitPID uint32
}
// ParseWindowArgs reads the window flags. ok is false when args hold
// anything else, which means command-line mode. No arguments is a plain
// window launch.
func ParseWindowArgs(args []string) (w WindowArgs, ok bool) {
for _, a := range args {
switch {
case a == flagBackground:
w.Background = true
case a == flagSafeMode:
w.SafeMode = true
case strings.HasPrefix(a, flagStartVM):
w.StartVM = strings.TrimPrefix(a, flagStartVM)
case strings.HasPrefix(a, flagStartDriver):
w.StartDriver = strings.TrimPrefix(a, flagStartDriver)
case strings.HasPrefix(a, flagStartResult):
w.StartResult = strings.TrimPrefix(a, flagStartResult)
case strings.HasPrefix(a, flagWaitPID):
pid, err := strconv.ParseUint(strings.TrimPrefix(a, flagWaitPID), 10, 32)
if err != nil || pid == 0 {
return WindowArgs{}, false
}
w.WaitPID = uint32(pid)
default:
return WindowArgs{}, false
}
}
return w, true
}
// Args is the inverse of ParseWindowArgs.
func (w WindowArgs) Args() []string {
var out []string
if w.Background {
out = append(out, flagBackground)
}
if w.SafeMode {
out = append(out, flagSafeMode)
}
if w.StartVM != "" {
out = append(out, flagStartVM+w.StartVM)
}
if w.StartDriver != "" {
out = append(out, flagStartDriver+w.StartDriver)
}
if w.StartResult != "" {
out = append(out, flagStartResult+w.StartResult)
}
if w.WaitPID != 0 {
out = append(out, flagWaitPID+strconv.FormatUint(uint64(w.WaitPID), 10))
}
return out
}
// StartResult is the JSON the window writes to WindowArgs.StartResult.
type StartResult struct {
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
}