Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Sources/ArgumentEncoding/PositionalArgument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,33 @@ extension Positional {
}
}

// MARK: Convenience initializers when Value: ArgumentGroup

extension Positional where Value: ArgumentGroup {
/// Initializes a new positional when not used as a `@propertyWrapper`
///
/// - Parameters
/// - wrappedValue: The underlying value
public init(value: Value) {
wrappedValue = value
unwrap = Self.unwrap(_:)
}

/// Initializes a new positional when used as a `@propertyWrapper`
///
/// - Parameters
/// - wrappedValue: The underlying value
public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
unwrap = Self.unwrap(_:)
}

@Sendable
public static func unwrap(_ value: Value) -> [String] {
value.arguments()
}
}

// MARK: ExpressibleBy...Literal conformances

extension Positional: ExpressibleByIntegerLiteral where Value: BinaryInteger, Value.IntegerLiteralType == Int {
Expand Down
9 changes: 9 additions & 0 deletions Tests/ArgumentEncodingTests/PositionalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ final class PositionalTests: XCTestCase {
let args = container.arguments()
XCTAssertEqual(args, ["positional-argument"])
}

func testPositionalArgumentGroup() throws {
let positional =
Positional(
value: Container(configuration: RawValueCustomStringConvertible(rawValue: "positional-argument"))
)
let args = positional.arguments()
XCTAssertEqual(args, ["positional-argument"])
}
}

private struct RawValueCustomStringConvertible: RawRepresentable, CustomStringConvertible {
Expand Down