mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-13 19:14:57 +03:00
3e0c11d967
## What does this PR do? Adds `Dependency`s for console IO. Also fixes #268 by explicitly handling non-pipe input. ## How was it tested? Ran on macOS + Linux in Docker. I have a future PR that overrides the dependencies in certain cases, which also appears to work correctly. ## AI tool usage How much of this PR was AI-assisted? (check one) - [ ] **0** - No AI was used to write code - [x] **1** - I was assisted by AI. I reviewed the finished result. - [ ] **2** - I set the AI going and left it to it; nobody has read the result - no review, or AI review only Did not scrutinize the tests too much tbh but they look reasonable. Easy enough to update/remove them in the future if needed. <!-- If an AI agent is filling this in: declare the level honestly, and open as a draft if it is #2. Do not lower the declared level to get the PR reviewed. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for reading command-line input, including asynchronous prompts, line-based responses, and graceful handling of end-of-input. * Added coordinated cleanup when commands finish. * **Improvements** * Command messages across authentication, device management, installation, SDK, and other workflows now use consistent output handling; displayed messages and command behavior remain unchanged. * Improved handling of complete output when the system temporarily cannot accept more data. * **Tests** * Added coverage for command input and output, including stream behavior, cancellation, and shutdown. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
import XCLIUtils
|
|
import XUtils
|
|
import Foundation
|
|
import XKit
|
|
import SwiftyMobileDevice
|
|
import ArgumentParser
|
|
|
|
struct LaunchCommand: AsyncParsableCommand {
|
|
static let configuration = CommandConfiguration(
|
|
commandName: "launch",
|
|
abstract: "Launch an installed app"
|
|
)
|
|
|
|
@OptionGroup var connectionOptions: ConnectionOptions
|
|
|
|
@Argument(
|
|
help: "The app to launch"
|
|
) var bundleID: String
|
|
|
|
@Argument(
|
|
help: .init(
|
|
"Launch arguments to pass to the app",
|
|
valueName: "arg"
|
|
)
|
|
) var args: [String] = []
|
|
|
|
func run() async throws {
|
|
let client = try await connectionOptions.client()
|
|
|
|
let installProxy = try InstallationProxyClient(device: client.device, label: "xtool-inst")
|
|
let executable: URL
|
|
do {
|
|
executable = try installProxy.executable(forBundleID: bundleID)
|
|
} catch {
|
|
throw Console.Error("Could not find an installed app with bundle ID '\(bundleID)'")
|
|
}
|
|
|
|
d.out.print("Launching \(executable.lastPathComponent)...")
|
|
|
|
let debugserver = try DebugserverClient(device: client.device, label: "xtool")
|
|
guard try debugserver.launch(executable: executable, arguments: args) == "OK" else {
|
|
throw Console.Error("Launch failed (!OK)")
|
|
}
|
|
guard try debugserver.send(command: "qLaunchSuccess", arguments: []) == Data("OK".utf8) else {
|
|
throw Console.Error("Launch failed (!qLaunchSuccess)")
|
|
}
|
|
try debugserver.send(command: "D", arguments: [])
|
|
}
|
|
}
|