Add headless JSON CLI#58
Open
plyrthn wants to merge 1 commit into
Open
Conversation
Adds non-interactive subcommands so shurectl can be scripted. Bare `shurectl`
still launches the TUI; with a subcommand it prints JSON and exits.
Commands:
- `shurectl get`: full device state as JSON
- `shurectl set <setting> <value>`: apply one setting, print the resulting state
- `shurectl set help`: list every setting, its accepted values, and the models
it applies to
- `shurectl preset list|save N|load N|delete N`: host-side presets
Output is JSON on stdout. On error it prints {"error": ...} and exits non-zero,
so callers can branch on the exit code.
- `headless.rs` (new): command dispatch, value parsing, the settings catalog
- `main.rs`: clap subcommands; apply_preset_to_device now takes &ShureDevice so
the TUI preset-load and `preset load` share it
- `Cargo.toml`: add serde_json
`get` reuses PresetSlot for its body, so the JSON field names and value tokens
match the on-disk preset format. `set` parses enum values into the existing
Ser* mirror types, so the tokens `get` emits are exactly the tokens `set`
accepts, and an unknown value reports the valid variants. One catalog() drives
`set help` and the per-model applicability check, so a setting that does not
apply to the connected model errors instead of silently no-opping. No protocol
changes; it calls the same device.rs methods the TUI does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds non-interactive subcommands so shurectl can be scripted. Bare
shurectlstill launches the TUI; with a subcommand it prints JSON and exits.Commands
shurectl get- full device state as JSONshurectl set <setting> <value>- apply one setting, print the resulting stateshurectl set help- list every setting, its accepted values, and the models it applies toshurectl preset list|save N|load N|delete N- host-side presetsOutput is JSON on stdout. On error it prints
{"error": ...}and exits non-zero, so callers can branch on the exit code.Changes
headless.rs(new) - command dispatch, value parsing, settings catalogmain.rs-get/set/presetsubcommands via clap;apply_preset_to_devicerefactored to take&ShureDeviceso the TUI preset-load andpreset loadshare itCargo.toml- addserde_jsonDesign
getreusesPresetSlotfor its body, so the JSON field names and value tokens match the on-disk preset formatsetparses enum values into the existingSer*mirror types, so the tokensgetemits are exactly the tokenssetaccepts, and an unknown value reports the valid variantscatalog()is the source of truth forset helpand the per-model applicability check, so a setting that does not apply to the connected model (e.g.phantomon an MV6) errors instead of silently no-oppingdevice.rsmethods the TUI doesTested
Against an MV6: get/set/preset round-trip, the help catalog, and the applicability and value-validation errors. Adds 10 unit tests for the parsers and catalog/dispatch consistency; fmt and clippy clean.