feat: Adds output values to some of the commands to allow them to be piped into other commands

This commit is contained in:
2024-12-16 12:28:38 -05:00
parent 1302b15ee2
commit 1429c51821
11 changed files with 112 additions and 64 deletions

View File

@@ -53,7 +53,7 @@ extension PlaybookClient.RunPlaybook.CreateOptions {
}
extension PlaybookClient.RunPlaybook.GenerateTemplateOptions {
func run() async throws {
func run() async throws -> String {
try await shared.run { arguments, _ in
arguments.append(contentsOf: [
"--tags", "repo-template",
@@ -67,16 +67,21 @@ extension PlaybookClient.RunPlaybook.GenerateTemplateOptions {
if !useVault {
arguments.append(contentsOf: ["--extra-vars", "use_vault=false"])
}
return templateDirectory
}
}
}
extension PlaybookClient.RunPlaybook.SharedRunOptions {
func run(_ apply: @Sendable @escaping (inout [String], Configuration) throws -> Void) async throws {
@discardableResult
func run<T>(
_ apply: @Sendable @escaping (inout [String], Configuration) throws -> T
) async throws -> T {
@Dependency(\.commandClient) var commandClient
try await commandClient.run(
return try await commandClient.run(
logging: loggingOptions,
quiet: quiet,
shell: shell
@@ -91,9 +96,9 @@ extension PlaybookClient.RunPlaybook.SharedRunOptions {
inventoryFilePath: inventoryFilePath
)
try apply(&arguments, configuration)
let output = try apply(&arguments, configuration)
return arguments
return (arguments, output)
}
}
}