Skip to content

Commit 20f08a9

Browse files
Merge pull request #7 from SwiftPackageIndex/general-improvements
General package improvements
2 parents c2b8d99 + dab00fe commit 20f08a9

File tree

11 files changed

+172
-188
lines changed

11 files changed

+172
-188
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
matrix:
3333
image: [
3434
'swift:5.8',
35-
'swiftlang/swift@sha256:f212429011a4c3592ffaa660fd78b5bc149e9df7920da02dfc0e7a761582fa10' # swiftlang/swift:nightly-5.9-focal 2023-08-16
35+
'swift:5.9'
3636
]
3737
container:
3838
image: ${{ matrix.image }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
/.build
33
/Packages
44
/*.xcodeproj
5-
.swiftpm
6-
.vscode/
5+
/.swiftpm
6+
/.vscode

Makefile

Lines changed: 0 additions & 43 deletions
This file was deleted.

ShellOut.podspec

Lines changed: 0 additions & 17 deletions
This file was deleted.

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/ShellOut.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ private extension TSCBasic.Process {
102102
environment: [String : String]? = nil,
103103
at: String? = nil
104104
) async throws -> (stdout: String, stderr: String) {
105-
let process = try Self.init(
105+
let actualCwd = try at.map { try .init(validating: $0) } ?? TSCBasic.localFileSystem.currentWorkingDirectory ?? .root
106+
let process = Self.init(
106107
arguments: [command] + arguments,
107108
environment: environment ?? ProcessEnv.vars,
108-
workingDirectory: at.map { try .init(validating: $0) } ?? TSCBasic.localFileSystem.currentWorkingDirectory ?? .root,
109+
workingDirectory: actualCwd,
109110
outputRedirection: .collect(redirectStderr: false),
110111
startNewProcessGroup: false,
111-
loggingHandler: nil
112+
loggingHandler: logger.map { logger in { logger.debug("\($0)", metadata: ["cwd": .string(actualCwd.pathString)]) } }
112113
)
113114

114115
try process.launch()

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)