File tree Expand file tree Collapse file tree 4 files changed +8
-21
lines changed Expand file tree Collapse file tree 4 files changed +8
-21
lines changed Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
-
4
3
public enum Argument : Equatable {
5
4
case quoted( QuotedString )
6
5
case verbatim( String )
7
6
8
- public init ( quoted string: String ) {
9
- self = . quoted( . init( string) )
7
+ public init ( quoted string: some StringProtocol ) {
8
+ self = . quoted( . init( . init ( string) ) )
10
9
}
11
10
12
- public init ( verbatim string: String ) {
13
- self = . verbatim( string)
11
+ public init ( verbatim string: some StringProtocol ) {
12
+ self = . verbatim( . init ( string) )
14
13
}
15
14
}
16
15
17
-
18
16
extension Argument : ExpressibleByStringLiteral {
19
17
public init ( stringLiteral value: StringLiteralType ) {
20
18
self = . quoted( . init( value) )
21
19
}
22
20
}
23
21
24
-
25
22
extension Argument : CustomStringConvertible {
26
23
public var description : String {
27
24
switch self {
@@ -33,19 +30,17 @@ extension Argument: CustomStringConvertible {
33
30
}
34
31
}
35
32
36
-
37
33
extension Argument {
38
34
public static func url( _ url: URL ) -> Self { url. absoluteString. verbatim }
39
35
}
40
36
41
37
42
- extension String {
38
+ extension StringProtocol {
43
39
public var quoted : Argument { . init( quoted: self ) }
44
40
public var verbatim : Argument { . init( verbatim: self ) }
45
41
}
46
42
47
-
48
- extension Array where Element == String {
43
+ extension Sequence < StringProtocol > {
49
44
public var quoted : [ Argument ] { map ( \. quoted) }
50
45
public var verbatim : [ Argument ] { map ( \. verbatim) }
51
46
}
Original file line number Diff line number Diff line change 1
1
import ShellQuote
2
2
3
-
4
3
public struct QuotedString : Equatable {
5
4
public var unquoted : String
6
5
public var quoted : String
@@ -11,7 +10,6 @@ public struct QuotedString: Equatable {
11
10
}
12
11
}
13
12
14
-
15
13
extension QuotedString : CustomStringConvertible {
16
14
public var description : String { quoted }
17
15
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public extension ShellOutCommand {
15
15
16
16
/// Create a file with a given name and contents (will overwrite any existing file with the same name)
17
17
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] )
19
19
}
20
20
21
21
/// Move a file from one path to another
Original file line number Diff line number Diff line change @@ -35,12 +35,6 @@ extension ShellOutError: LocalizedError {
35
35
36
36
private extension Data {
37
37
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 } ) )
45
39
}
46
40
}
You can’t perform that action at this time.
0 commit comments