Skip to content

Commit 19eb7c3

Browse files
committed
Add Argument conveniences
1 parent b1db153 commit 19eb7c3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Sources/Argument.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import Foundation
2+
3+
14
public enum Argument {
25
case quoted(QuotedString)
36
case verbatim(String)
@@ -21,11 +24,23 @@ public enum Argument {
2124
}
2225

2326

27+
extension Argument: ExpressibleByStringLiteral {
28+
public init(stringLiteral value: StringLiteralType) {
29+
self = .quoted(.init(value))
30+
}
31+
}
32+
33+
2434
extension Argument: CustomStringConvertible {
2535
public var description: String { string }
2636
}
2737

2838

39+
extension Argument {
40+
public static func url(_ url: URL) -> Self { url.absoluteString.verbatim }
41+
}
42+
43+
2944
extension String {
3045
public var quoted: Argument { .init(quoted: self) }
3146
public var verbatim: Argument { .init(verbatim: self) }

Tests/ShellOutTests/ShellOutTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,14 @@ class ShellOutTests: XCTestCase {
215215
arguments: ["foo ; echo bar".verbatim]),
216216
"foo\nbar")
217217
}
218+
219+
func test_Argument_ExpressibleByStringLiteral() throws {
220+
XCTAssertEqual(("foo" as Argument).string, "foo")
221+
XCTAssertEqual(("foo bar" as Argument).string, "'foo bar'")
222+
}
223+
224+
func test_Argument_url() throws {
225+
XCTAssertEqual(Argument.url(.init(string: "https://example.com")!).string,
226+
"https://example.com")
227+
}
218228
}

0 commit comments

Comments
 (0)