Skip to content

Commit 27af7ad

Browse files
committed
Remove old version
1 parent deba117 commit 27af7ad

File tree

1 file changed

+0
-159
lines changed

1 file changed

+0
-159
lines changed

Sources/ShellOut.swift

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,6 @@ import Algorithms
5555
)
5656
}
5757

58-
@discardableResult public func shellOutOldVersion(
59-
to command: SafeString,
60-
arguments: [Argument] = [],
61-
at path: String = ".",
62-
process: Foundation.Process = .init(),
63-
outputHandle: FileHandle? = nil,
64-
errorHandle: FileHandle? = nil,
65-
environment: [String : String]? = nil
66-
) throws -> (stdout: String, stderr: String) {
67-
let command = "cd \(path.escapingSpaces) && \(command) \(arguments.map(\.string).joined(separator: " "))"
68-
69-
return try process.launchBashOldVersion(
70-
with: command,
71-
outputHandle: outputHandle,
72-
errorHandle: errorHandle,
73-
environment: environment
74-
)
75-
}
76-
7758
/**
7859
* Run a pre-defined shell command using Bash
7960
*
@@ -111,25 +92,6 @@ import Algorithms
11192
)
11293
}
11394

114-
@discardableResult public func shellOutOldVersion(
115-
to command: ShellOutCommand,
116-
at path: String = ".",
117-
process: Foundation.Process = .init(),
118-
outputHandle: FileHandle? = nil,
119-
errorHandle: FileHandle? = nil,
120-
environment: [String : String]? = nil
121-
) throws -> (stdout: String, stderr: String) {
122-
try shellOutOldVersion(
123-
to: command.command,
124-
arguments: command.arguments,
125-
at: path,
126-
process: process,
127-
outputHandle: outputHandle,
128-
errorHandle: errorHandle,
129-
environment: environment
130-
)
131-
}
132-
13395
/// Structure used to pre-define commands for use with ShellOut
13496
public struct ShellOutCommand {
13597
/// The string that makes up the command that should be run on the command line
@@ -482,105 +444,6 @@ private extension TSCBasic.Process {
482444
}
483445
}
484446

485-
extension Foundation.Process {
486-
@discardableResult func launchBashOldVersion(with command: String, outputHandle: FileHandle? = nil, errorHandle: FileHandle? = nil, environment: [String : String]? = nil) throws -> (stdout: String, stderr: String) {
487-
#if os(Linux)
488-
executableURL = URL(fileURLWithPath: "/bin/bash")
489-
#else
490-
launchPath = "/bin/bash"
491-
#endif
492-
arguments = ["-c", command]
493-
494-
if let environment = environment {
495-
self.environment = environment
496-
}
497-
498-
// Because FileHandle's readabilityHandler might be called from a
499-
// different queue from the calling queue, avoid a data race by
500-
// protecting reads and writes to outputData and errorData on
501-
// a single dispatch queue.
502-
let outputQueue = DispatchQueue(label: "bash-output-queue")
503-
504-
var outputData = Data()
505-
var errorData = Data()
506-
507-
let outputPipe = Pipe()
508-
standardOutput = outputPipe
509-
510-
let errorPipe = Pipe()
511-
standardError = errorPipe
512-
513-
#if !os(Linux)
514-
outputPipe.fileHandleForReading.readabilityHandler = { handler in
515-
let data = handler.availableData
516-
outputQueue.async {
517-
outputData.append(data)
518-
outputHandle?.write(data)
519-
}
520-
}
521-
522-
errorPipe.fileHandleForReading.readabilityHandler = { handler in
523-
let data = handler.availableData
524-
outputQueue.async {
525-
errorData.append(data)
526-
errorHandle?.write(data)
527-
}
528-
}
529-
#endif
530-
531-
#if os(Linux)
532-
try run()
533-
#else
534-
launch()
535-
#endif
536-
537-
#if os(Linux)
538-
outputQueue.sync {
539-
outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
540-
errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
541-
}
542-
#endif
543-
544-
waitUntilExit()
545-
546-
if let handle = outputHandle, !handle.isStandard {
547-
handle.closeFile()
548-
}
549-
550-
if let handle = errorHandle, !handle.isStandard {
551-
handle.closeFile()
552-
}
553-
554-
#if !os(Linux)
555-
outputPipe.fileHandleForReading.readabilityHandler = nil
556-
errorPipe.fileHandleForReading.readabilityHandler = nil
557-
#endif
558-
559-
// Block until all writes have occurred to outputData and errorData,
560-
// and then read the data back out.
561-
return try outputQueue.sync {
562-
if terminationStatus != 0 {
563-
throw ShellOutError(
564-
terminationStatus: terminationStatus,
565-
errorData: errorData,
566-
outputData: outputData
567-
)
568-
}
569-
570-
return (stdout: outputData.shellOutput(), stderr: errorData.shellOutput())
571-
}
572-
}
573-
574-
}
575-
576-
private extension FileHandle {
577-
var isStandard: Bool {
578-
return self === FileHandle.standardOutput ||
579-
self === FileHandle.standardError ||
580-
self === FileHandle.standardInput
581-
}
582-
}
583-
584447
private extension Data {
585448
func shellOutput() -> String {
586449
let output = String(decoding: self, as: UTF8.self)
@@ -593,25 +456,3 @@ private extension Data {
593456

594457
}
595458
}
596-
597-
private extension String {
598-
var escapingSpaces: String {
599-
return replacingOccurrences(of: " ", with: "\\ ")
600-
}
601-
602-
func appending(argument: String) -> String {
603-
return "\(self) \"\(argument)\""
604-
}
605-
606-
func appending(arguments: [String]) -> String {
607-
return appending(argument: arguments.joined(separator: "\" \""))
608-
}
609-
610-
mutating func append(argument: String) {
611-
self = appending(argument: argument)
612-
}
613-
614-
mutating func append(arguments: [String]) {
615-
self = appending(arguments: arguments)
616-
}
617-
}

0 commit comments

Comments
 (0)