@@ -15,6 +15,7 @@ import Dispatch
15
15
* - parameter command: The command to run
16
16
* - parameter arguments: The arguments to pass to the command
17
17
* - parameter path: The path to execute the commands at (defaults to current folder)
18
+ * - parameter process: Which process to use to perform the command (default: A new one)
18
19
* - parameter outputHandle: Any `FileHandle` that any output (STDOUT) should be redirected to
19
20
* (at the moment this is only supported on macOS)
20
21
* - parameter errorHandle: Any `FileHandle` that any error output (STDERR) should be redirected to
@@ -26,21 +27,29 @@ import Dispatch
26
27
* Use this function to "shell out" in a Swift script or command line tool
27
28
* For example: `shellOut(to: "mkdir", arguments: ["NewFolder"], at: "~/CurrentFolder")`
28
29
*/
29
- @discardableResult public func shellOut( to command: String ,
30
- arguments: [ String ] = [ ] ,
31
- at path: String = " . " ,
32
- outputHandle: FileHandle ? = nil ,
33
- errorHandle: FileHandle ? = nil ) throws -> String {
34
- let process = Process ( )
30
+ @discardableResult public func shellOut(
31
+ to command: String ,
32
+ arguments: [ String ] = [ ] ,
33
+ at path: String = " . " ,
34
+ process: Process = . init( ) ,
35
+ outputHandle: FileHandle ? = nil ,
36
+ errorHandle: FileHandle ? = nil
37
+ ) throws -> String {
35
38
let command = " cd \( path. escapingSpaces) && \( command) \( arguments. joined ( separator: " " ) ) "
36
- return try process. launchBash ( with: command, outputHandle: outputHandle, errorHandle: errorHandle)
39
+
40
+ return try process. launchBash (
41
+ with: command,
42
+ outputHandle: outputHandle,
43
+ errorHandle: errorHandle
44
+ )
37
45
}
38
46
39
47
/**
40
48
* Run a series of shell commands using Bash
41
49
*
42
50
* - parameter commands: The commands to run
43
51
* - parameter path: The path to execute the commands at (defaults to current folder)
52
+ * - parameter process: Which process to use to perform the command (default: A new one)
44
53
* - parameter outputHandle: Any `FileHandle` that any output (STDOUT) should be redirected to
45
54
* (at the moment this is only supported on macOS)
46
55
* - parameter errorHandle: Any `FileHandle` that any error output (STDERR) should be redirected to
@@ -52,19 +61,30 @@ import Dispatch
52
61
* Use this function to "shell out" in a Swift script or command line tool
53
62
* For example: `shellOut(to: ["mkdir NewFolder", "cd NewFolder"], at: "~/CurrentFolder")`
54
63
*/
55
- @discardableResult public func shellOut( to commands: [ String ] ,
56
- at path: String = " . " ,
57
- outputHandle: FileHandle ? = nil ,
58
- errorHandle: FileHandle ? = nil ) throws -> String {
64
+ @discardableResult public func shellOut(
65
+ to commands: [ String ] ,
66
+ at path: String = " . " ,
67
+ process: Process = . init( ) ,
68
+ outputHandle: FileHandle ? = nil ,
69
+ errorHandle: FileHandle ? = nil
70
+ ) throws -> String {
59
71
let command = commands. joined ( separator: " && " )
60
- return try shellOut ( to: command, at: path, outputHandle: outputHandle, errorHandle: errorHandle)
72
+
73
+ return try shellOut (
74
+ to: command,
75
+ at: path,
76
+ process: process,
77
+ outputHandle: outputHandle,
78
+ errorHandle: errorHandle
79
+ )
61
80
}
62
81
63
82
/**
64
83
* Run a pre-defined shell command using Bash
65
84
*
66
85
* - parameter command: The command to run
67
86
* - parameter path: The path to execute the commands at (defaults to current folder)
87
+ * - parameter process: Which process to use to perform the command (default: A new one)
68
88
* - parameter outputHandle: Any `FileHandle` that any output (STDOUT) should be redirected to
69
89
* - parameter errorHandle: Any `FileHandle` that any error output (STDERR) should be redirected to
70
90
*
@@ -76,11 +96,20 @@ import Dispatch
76
96
*
77
97
* See `ShellOutCommand` for more info.
78
98
*/
79
- @discardableResult public func shellOut( to command: ShellOutCommand ,
80
- at path: String = " . " ,
81
- outputHandle: FileHandle ? = nil ,
82
- errorHandle: FileHandle ? = nil ) throws -> String {
83
- return try shellOut ( to: command. string, at: path, outputHandle: outputHandle, errorHandle: errorHandle)
99
+ @discardableResult public func shellOut(
100
+ to command: ShellOutCommand ,
101
+ at path: String = " . " ,
102
+ process: Process = . init( ) ,
103
+ outputHandle: FileHandle ? = nil ,
104
+ errorHandle: FileHandle ? = nil
105
+ ) throws -> String {
106
+ return try shellOut (
107
+ to: command. string,
108
+ at: path,
109
+ process: process,
110
+ outputHandle: outputHandle,
111
+ errorHandle: errorHandle
112
+ )
84
113
}
85
114
86
115
/// Structure used to pre-define commands for use with ShellOut
0 commit comments