惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
B
Blog
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
量子位
博客园 - 叶小钗
T
Tailwind CSS Blog
小众软件
小众软件
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
博客园_首页
I
InfoQ
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test(macos): cover root command dispatch (#93705) · openc...
markoub · 2026-06-17 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,41 +1,68 @@

11

import Foundation

22
3-

private struct RootCommand {

3+

struct RootCommand: Equatable {

44

var name: String

55

var args: [String]

66

}

77
8+

enum RootCommandAction: Equatable {

9+

case usage

10+

case connect([String])

11+

case configureRemote([String])

12+

case discover([String])

13+

case wizard([String])

14+

case unknown(exitCode: Int32)

15+

}

16+
817

@main

918

struct OpenClawMacCLI {

1019

static func main() async {

1120

let args = Array(CommandLine.arguments.dropFirst())

12-

let command = parseRootCommand(args)

13-

switch command?.name {

14-

case nil:

21+

switch resolveRootCommandAction(args) {

22+

case .usage:

1523

printUsage()

16-

case "-h", "--help", "help":

17-

printUsage()

18-

case "connect":

19-

await runConnect(command?.args ?? [])

20-

case "configure-remote":

21-

runConfigureRemote(command?.args ?? [])

22-

case "discover":

23-

await runDiscover(command?.args ?? [])

24-

case "wizard":

25-

await runWizardCommand(command?.args ?? [])

26-

default:

24+

case let .connect(commandArgs):

25+

await runConnect(commandArgs)

26+

case let .configureRemote(commandArgs):

27+

runConfigureRemote(commandArgs)

28+

case let .discover(commandArgs):

29+

await runDiscover(commandArgs)

30+

case let .wizard(commandArgs):

31+

await runWizardCommand(commandArgs)

32+

case let .unknown(exitCode):

2733

fputs("openclaw-mac: unknown command\n", stderr)

2834

printUsage()

29-

exit(1)

35+

exit(exitCode)

3036

}

3137

}

3238

}

3339
34-

private func parseRootCommand(_ args: [String]) -> RootCommand? {

40+

func parseRootCommand(_ args: [String]) -> RootCommand? {

3541

guard let first = args.first else { return nil }

3642

return RootCommand(name: first, args: Array(args.dropFirst()))

3743

}

3844
45+

func resolveRootCommandAction(_ args: [String]) -> RootCommandAction {

46+

guard let command = parseRootCommand(args) else {

47+

return .usage

48+

}

49+
50+

switch command.name {

51+

case "-h", "--help", "help":

52+

return .usage

53+

case "connect":

54+

return .connect(command.args)

55+

case "configure-remote":

56+

return .configureRemote(command.args)

57+

case "discover":

58+

return .discover(command.args)

59+

case "wizard":

60+

return .wizard(command.args)

61+

default:

62+

return .unknown(exitCode: 1)

63+

}

64+

}

65+
3966

private func printUsage() {

4067

print("""

4168

openclaw-mac

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,38 @@

1+

import Testing

2+

@testable import OpenClawMacCLI

3+
4+

struct RootCommandParserTests {

5+

@Test func `parse root command returns nil for empty args`() {

6+

#expect(parseRootCommand([]) == nil)

7+

}

8+
9+

@Test func `parse root command splits command name and args`() throws {

10+

let command = try #require(parseRootCommand(["connect", "--json", "--timeout", "3000"]))

11+
12+

#expect(command.name == "connect")

13+

#expect(command.args == ["--json", "--timeout", "3000"])

14+

}

15+
16+

@Test func `help aliases resolve to usage`() {

17+

for args in [[], ["-h"], ["--help"], ["help"]] {

18+

#expect(resolveRootCommandAction(args) == .usage)

19+

}

20+

}

21+
22+

@Test func `known commands preserve trailing args`() {

23+

#expect(resolveRootCommandAction(["connect", "--json"]) == .connect(["--json"]))

24+

#expect(

25+

resolveRootCommandAction(["configure-remote", "--ssh-target", "alice@example.com"])

26+

== .configureRemote(["--ssh-target", "alice@example.com"]))

27+

#expect(resolveRootCommandAction(["discover", "--include-local"]) == .discover(["--include-local"]))

28+

#expect(resolveRootCommandAction(["wizard", "--mode", "local"]) == .wizard(["--mode", "local"]))

29+

}

30+
31+

@Test func `unknown command resolves to nonzero exit action`() {

32+

#expect(resolveRootCommandAction(["nope"]) == .unknown(exitCode: 1))

33+

}

34+
35+

@Test func `command names remain case sensitive`() {

36+

#expect(resolveRootCommandAction(["Connect"]) == .unknown(exitCode: 1))

37+

}

38+

}