feat: Updates to check if playbook is installed prior to running any of the commands, updates tests.

This commit is contained in:
2024-12-19 11:22:16 -05:00
parent 9ec86bc523
commit beb48f10a5
5 changed files with 39 additions and 5 deletions

View File

@@ -120,7 +120,11 @@ struct LiveFileClient: Sendable {
func isDirectory(_ url: URL) -> Bool {
var isDirectory: ObjCBool = false
manager.fileExists(atPath: url.cleanFilePath, isDirectory: &isDirectory)
#if os(Linux)
_ = manager.fileExists(atPath: url.cleanFilePath, isDirectory: &isDirectory)
#else
manager.fileExists(atPath: url.cleanFilePath, isDirectory: &isDirectory)
#endif
return isDirectory.boolValue
}

View File

@@ -81,6 +81,8 @@ extension PlaybookClient.RunPlaybook.SharedRunOptions {
) async throws -> T {
@Dependency(\.commandClient) var commandClient
try await ensurePlaybookExists()
return try await commandClient.run(
logging: loggingOptions,
quiet: quiet,
@@ -101,6 +103,17 @@ extension PlaybookClient.RunPlaybook.SharedRunOptions {
return (arguments, output)
}
}
private func ensurePlaybookExists() async throws {
@Dependency(\.fileClient) var fileClient
@Dependency(\.playbookClient.repository) var repository
let directory = try await repository.directory()
let exists = try await fileClient.isDirectory(URL(filePath: directory))
if !exists {
try await repository.install()
}
}
}
@_spi(Internal)