Skip to content

Commit 42e0bea

Browse files
committed
Minor whitespace cleanups, make some of the String usage a little more flexible (via StringProtocol)
1 parent b4aa0db commit 42e0bea

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

Sources/Argument.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import Foundation
22

3-
43
public enum Argument: Equatable {
54
case quoted(QuotedString)
65
case verbatim(String)
76

8-
public init(quoted string: String) {
9-
self = .quoted(.init(string))
7+
public init(quoted string: some StringProtocol) {
8+
self = .quoted(.init(.init(string)))
109
}
1110

12-
public init(verbatim string: String) {
13-
self = .verbatim(string)
11+
public init(verbatim string: some StringProtocol) {
12+
self = .verbatim(.init(string))
1413
}
1514
}
1615

17-
1816
extension Argument: ExpressibleByStringLiteral {
1917
public init(stringLiteral value: StringLiteralType) {
2018
self = .quoted(.init(value))
2119
}
2220
}
2321

24-
2522
extension Argument: CustomStringConvertible {
2623
public var description: String {
2724
switch self {
@@ -33,19 +30,17 @@ extension Argument: CustomStringConvertible {
3330
}
3431
}
3532

36-
3733
extension Argument {
3834
public static func url(_ url: URL) -> Self { url.absoluteString.verbatim }
3935
}
4036

4137

42-
extension String {
38+
extension StringProtocol {
4339
public var quoted: Argument { .init(quoted: self) }
4440
public var verbatim: Argument { .init(verbatim: self) }
4541
}
4642

47-
48-
extension Array where Element == String {
43+
extension Sequence<StringProtocol> {
4944
public var quoted: [Argument] { map(\.quoted) }
5045
public var verbatim: [Argument] { map(\.verbatim) }
5146
}

Sources/QuotedString.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ShellQuote
22

3-
43
public struct QuotedString: Equatable {
54
public var unquoted: String
65
public var quoted: String
@@ -11,7 +10,6 @@ public struct QuotedString: Equatable {
1110
}
1211
}
1312

14-
1513
extension QuotedString: CustomStringConvertible {
1614
public var description: String { quoted }
1715
}

Sources/ShellOutCommand+other.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension ShellOutCommand {
1515

1616
/// Create a file with a given name and contents (will overwrite any existing file with the same name)
1717
static func createFile(named name: String, contents: String) -> ShellOutCommand {
18-
.bash(arguments: ["-c", #"echo \#(contents.quoted) > \#(name.quoted)"#.verbatim])
18+
.bash(arguments: ["-c", "echo \(contents.quoted) > \(name.quoted)".verbatim])
1919
}
2020

2121
/// Move a file from one path to another

Sources/ShellOutError.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ extension ShellOutError: LocalizedError {
3535

3636
private extension Data {
3737
func shellOutput() -> String {
38-
let output = String(decoding: self, as: UTF8.self)
39-
40-
guard !output.hasSuffix("\n") else {
41-
return String(output.dropLast())
42-
}
43-
44-
return output
38+
.init(String(decoding: self, as: UTF8.self).trimmingSuffix(while: { $0.isNewline }))
4539
}
4640
}

0 commit comments

Comments
 (0)