-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWithOutput.swift
35 lines (30 loc) · 1.01 KB
/
WithOutput.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import SwiftCICDCore
public struct WithOutput<Input, WrappedAction: Action>: Action {
let wrappedAction: (Input) -> WrappedAction
var getInput: () throws -> Input
@_disfavoredOverload
public init(
_ output: KeyPath<OutputValues, Input>,
@ActionBuilder _ action: @escaping (Input) -> WrappedAction
) {
wrappedAction = action
getInput = { Self.context.outputs[keyPath: output] }
}
public init(
_ output: KeyPath<OutputValues, Optional<Input>>,
file: StaticString = #file, line: UInt = #line,
@ActionBuilder _ action: @escaping (Input) -> WrappedAction
) {
wrappedAction = action
getInput = {
guard let input = Self.context.outputs[keyPath: output] else {
throw ActionError("Output was missing.", file: file, line: line)
}
return input
}
}
public func run() async throws {
let input = try getInput()
try await self.run(wrappedAction(input))
}
}