mirror of
https://github.com/MobAI-App/simslim.git
synced 2026-10-19 10:18:32 +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.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSimctlArgsForSet(t *testing.T) {
|
|
t.Run("default set omits --set", func(t *testing.T) {
|
|
got := simctlArgsForSet("", "boot", "UDID")
|
|
want := []string{"simctl", "boot", "UDID"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgsForSet() = %v, want %v", got, want)
|
|
}
|
|
})
|
|
t.Run("named set injects --set before the subcommand", func(t *testing.T) {
|
|
got := simctlArgsForSet("testing", "boot", "UDID")
|
|
want := []string{"simctl", "--set", "testing", "boot", "UDID"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgsForSet() = %v, want %v", got, want)
|
|
}
|
|
})
|
|
t.Run("simctlArgs maps a set name to its --set token", func(t *testing.T) {
|
|
got := simctlArgs("testing", "list", "devices", "-j")
|
|
want := []string{"simctl", "--set", "testing", "list", "devices", "-j"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("simctlArgs() = %v, want %v", got, want)
|
|
}
|
|
if got := simctlArgs("default", "list"); !reflect.DeepEqual(got, []string{"simctl", "list"}) {
|
|
t.Errorf("simctlArgs(default) = %v, want no --set", got)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestDeviceSetToken(t *testing.T) {
|
|
if got := deviceSetToken("default"); got != "" {
|
|
t.Errorf("deviceSetToken(default) = %q, want empty", got)
|
|
}
|
|
if got := deviceSetToken("testing"); got != "testing" {
|
|
t.Errorf("deviceSetToken(testing) = %q, want testing", got)
|
|
}
|
|
if deviceSetToken("unknown-set") != "" {
|
|
t.Error("an unknown set name should fall back to the default token")
|
|
}
|
|
}
|
|
|
|
func TestRegisterDeviceSetRoutes(t *testing.T) {
|
|
extraDeviceSets = nil
|
|
defer func() { extraDeviceSets = nil }()
|
|
registerDeviceSet("/custom/set")
|
|
// A registered set becomes discoverable like any other.
|
|
if deviceSetToken("/custom/set") != "/custom/set" {
|
|
t.Errorf("registered set not resolvable by name")
|
|
}
|
|
// A custom set's simctl args carry it as --set.
|
|
if got := simctlArgsForSet("/custom/set", "boot", "U"); !reflect.DeepEqual(got, []string{"simctl", "--set", "/custom/set", "boot", "U"}) {
|
|
t.Errorf("simctlArgsForSet(custom) = %v", got)
|
|
}
|
|
}
|