cli: magpie settings list|get|set|reset, through the window's own save (#4745)
Stage 1 of #4745 (StringKe): every setting POST /api/settings saves can be read and set from the terminal. - internal/settingsapi holds the save the handler made: Merge (the carry of keys a page leaves out, moved verbatim from api.go, plus upstream's RouterNote line), the vision/imageGen/searcher checks, settings.Save's own checks, catalog.Touched. POST /api/settings and `magpie settings` both call settingsapi.Apply, so a value is checked and saved one way. It sits outside internal/gui so the nogui build has it. - `magpie settings` (list, the default, with value, default and choices; get; set; reset to settings.Defaults()), --json on list and get. Body sends the whole file with one key changed, so a key the save keeps when absent (noBird, refusalRetries, ...) is set even to off. A flag where a key or value goes, an unknown key (with near matches named) or a refused value writes nothing and exits 1; --help prints usage. - Parity guards: TestKeysAreWhatTheSaveWrites (each Settings field sent changed on its own; what the save takes must equal Keys), TestSettingsCLISetsWhatTheWindowSaves (every key the page's prefsKeep and savePrefs send is a key), TestEveryRouteHasACommandOrIsNamed (each /api route has a command or a reason in notYet, which later stages shrink; 36 have one now). - Item 3 of the stage (per-provider CLI-only fields in the window) is left for stage 2. - The open app's in-process follow-ups (fonts, Dock, tray menu, alerts, language, update re-check) run only from the window's save: #4752. Run (mote, at the pushed head1c3591b5d+ this): - gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; GOOS=linux go build -tags nogui; GOOS=windows go build: clean (before rebase, the vets again after). - go test internal/settingsapi, internal/settings, internal/cli: ok. internal/gui -run Settings|Prefs|Keep after the rebase: ok. The full internal/gui run before the rebase had three reds: TestSettingsSaveKeepsWhatItDoesNotSend (BusyLoad, fixed on main inb646a9127), TestColdTurnsTaken (fixed on main in647323409) and TestMainWindowCorners/macOS_26_SDK (#3949, mote is macOS 27). - Real run in a sandbox HOME on mote with a magpie built from this: settings --help / help, list, get, set theme dark, noBird on, redactWords "acme, globex", usageAlert 85; refused theme neon, `them` (names theme), usageAlert lots, trayUsageEvery 4, vision nobody/nothing, each exit 1 with settings.json unchanged; set usageAlert --help printed usage and wrote nothing. Then `magpie web` with MAGPIE_WEB_KEY: GET /api/settings read back each value the CLI set; POST /api/settings lang ja, then `settings get lang` said ja; reset theme gave system. Broken by hand, each red, then put back: noBird dropped from Keys (TestKeys, TestBodySetsOneKeyOnly, the CLI set test and the GUI parity test red); Body dropping false values (TestBodySetsOneKeyOnly and the CLI "noBird off" check red); a route taken out of notYet and another renamed (TestEveryRouteHasACommandOrIsNamed red, 3 errors). On the old code the new tests don't compile (no settingsapi, no command). Not tried: a real run on Windows or Linux; the live app reacting to a CLI write while open (#4752); the GUI node suite (no page file changed).
This commit is contained in:
@@ -78,6 +78,8 @@ func helpFor(args []string) string {
|
||||
return githubUsage
|
||||
case "claude-code":
|
||||
return claudeCodeUsage
|
||||
case "settings":
|
||||
return settingsUsage
|
||||
case "list":
|
||||
cmd = "ls"
|
||||
case "account":
|
||||
|
||||
Reference in New Issue
Block a user