mirror of
https://github.com/MobAI-App/simslim.git
synced 2026-10-04 21:56:47 +02:00
Replace the hand-rolled argument handling with the urfave/cli/v3 command tree (the project's only dependency; no runtime transitive deps). This removes the manual command switch, parseInterspersedFlags, jsonOption, and extractDeviceSets in favor of the library's dispatch and flag parsing. The command surface is unchanged: same commands, flags, arguments, JSON output, error format (simslim: <msg>, exit 1), and unknown-command/usage handling (exit 2). Flags may still appear before or after positional args (v3 parses flags anywhere by default). --set is now a global flag inherited by every subcommand, registered in its flag Action with last-wins, comma-separated semantics. main still owns version, help, and the macOS guard; the root usage text is preserved verbatim. The command tree lives in app.go (newApp); each subcommand's Action is a cmd* function in main.go reading flags via cmd.Bool/String and positionals via cmd.Args(). Unit tests for the removed helpers are replaced by app_test.go, which drives newApp through Run.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
// DeviceSummary is the stable, machine-readable representation used by the
|
|
// macOS app and other integrations. managedDisabled is omitted for shutdown
|
|
// simulators because launchd state can only be read while a simulator is booted.
|
|
type DeviceSummary struct {
|
|
Device
|
|
ManagedDisabled *int `json:"managedDisabled,omitempty"`
|
|
ManagedTotal int `json:"managedTotal"`
|
|
StatusError string `json:"statusError,omitempty"`
|
|
Memory *Measurement `json:"memory,omitempty"`
|
|
MemoryError string `json:"memoryError,omitempty"`
|
|
}
|
|
|
|
type StatusOutput struct {
|
|
Status
|
|
Verdict string `json:"verdict"`
|
|
Dropped []DroppedCategory `json:"dropped,omitempty"` // only when `status --dropped` is requested
|
|
}
|
|
|
|
// DroppedCategory lists the managed daemons a category has disabled on a
|
|
// simulator, alongside the feature that stops working as a result.
|
|
type DroppedCategory struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Downside string `json:"downside"`
|
|
Labels []string `json:"labels"`
|
|
}
|
|
|
|
// SimulatorMutationOutput is returned by simulator-management commands so the
|
|
// GUI can refresh and, for clone, select the newly created device.
|
|
type SimulatorMutationOutput struct {
|
|
Action string `json:"action"`
|
|
UDID string `json:"udid"`
|
|
Name string `json:"name,omitempty"`
|
|
SourceUDID string `json:"sourceUdid,omitempty"`
|
|
}
|
|
|
|
type DiskMeasurement struct {
|
|
Bytes int64 `json:"bytes"`
|
|
}
|
|
|
|
func writeJSON(value any) error {
|
|
encoder := json.NewEncoder(os.Stdout)
|
|
encoder.SetIndent("", " ")
|
|
return encoder.Encode(value)
|
|
}
|