File tree 2 files changed +36
-0
lines changed
Tests/ArgumentEncodingTests
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,33 @@ extension Positional {
224
224
}
225
225
}
226
226
227
+ // MARK: Convenience initializers when Value: ArgumentGroup
228
+
229
+ extension Positional where Value: ArgumentGroup {
230
+ /// Initializes a new positional when not used as a `@propertyWrapper`
231
+ ///
232
+ /// - Parameters
233
+ /// - wrappedValue: The underlying value
234
+ public init ( value: Value ) {
235
+ wrappedValue = value
236
+ unwrap = Self . unwrap ( _: )
237
+ }
238
+
239
+ /// Initializes a new positional when used as a `@propertyWrapper`
240
+ ///
241
+ /// - Parameters
242
+ /// - wrappedValue: The underlying value
243
+ public init ( wrappedValue: Value ) {
244
+ self . wrappedValue = wrappedValue
245
+ unwrap = Self . unwrap ( _: )
246
+ }
247
+
248
+ @Sendable
249
+ public static func unwrap( _ value: Value ) -> [ String ] {
250
+ value. arguments ( )
251
+ }
252
+ }
253
+
227
254
// MARK: ExpressibleBy...Literal conformances
228
255
229
256
extension Positional : ExpressibleByIntegerLiteral where Value: BinaryInteger , Value. IntegerLiteralType == Int {
Original file line number Diff line number Diff line change @@ -26,6 +26,15 @@ final class PositionalTests: XCTestCase {
26
26
let args = container. arguments ( )
27
27
XCTAssertEqual ( args, [ " positional-argument " ] )
28
28
}
29
+
30
+ func testPositionalArgumentGroup( ) throws {
31
+ let positional =
32
+ Positional (
33
+ value: Container ( configuration: RawValueCustomStringConvertible ( rawValue: " positional-argument " ) )
34
+ )
35
+ let args = positional. arguments ( )
36
+ XCTAssertEqual ( args, [ " positional-argument " ] )
37
+ }
29
38
}
30
39
31
40
private struct RawValueCustomStringConvertible : RawRepresentable , CustomStringConvertible {
You can’t perform that action at this time.
0 commit comments