You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/SwiftlyCore/ModeledCommandLine.swift
+65-14Lines changed: 65 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,6 @@ import Foundation
2
2
import Subprocess
3
3
import SystemPackage
4
4
5
-
publicenumCommandLineError:Error{
6
-
case invalidArgs
7
-
case errorExit(exitCode:Int32, program:String)
8
-
case unknownVersion
9
-
}
10
-
11
5
publicprotocolRunnable{
12
6
func config()->Configuration
13
7
}
@@ -24,6 +18,7 @@ extension Runnable {
24
18
error:Error=.discarded
25
19
)asyncthrows->CollectedResult<Output,Error>{
26
20
varc=self.config()
21
+
27
22
// TODO: someday the configuration might have its own environment from the modeled commands. That will require this to be able to merge the environment from the commands with the provided environment.
28
23
c.environment = environment
29
24
@@ -40,6 +35,7 @@ extension Runnable {
40
35
quiet:Bool=false,
41
36
)asyncthrows{
42
37
varc=self.config()
38
+
43
39
// TODO: someday the configuration might have its own environment from the modeled commands. That will require this to be able to merge the environment from the commands with the provided environment.
44
40
c.environment = environment
45
41
@@ -59,23 +55,78 @@ extension Runnable {
59
55
60
56
publicprotocolOutput:Runnable{}
61
57
62
-
// TODO: look into making this something that can be Decodable (i.e. streamable)
63
58
extensionOutput{
64
59
publicfunc output(
65
60
environment:Environment=.inherit,
66
-
limit:Int
61
+
limit:Int,
62
+
quiet:Bool=false
67
63
)asyncthrows->String?{
68
64
varc=self.config()
65
+
69
66
// TODO: someday the configuration might have its own environment from the modeled commands. That will require this to be able to merge the environment from the commands with the provided environment.
70
67
c.environment = environment
71
68
72
-
letoutput=tryawaitSubprocess.run(
73
-
self.config(),
74
-
output:.string(limit: limit),
75
-
error:.standardError
76
-
)
69
+
if !quiet {
70
+
letresult=tryawaitSubprocess.run(
71
+
self.config(),
72
+
output:.string(limit: limit),
73
+
error:.standardError
74
+
)
77
75
78
-
return output.standardOutput
76
+
if !result.terminationStatus.isSuccess {
77
+
throwRunProgramError(terminationStatus: result.terminationStatus, config: c)
78
+
}
79
+
80
+
return result.standardOutput
81
+
}else{
82
+
letresult=tryawaitSubprocess.run(
83
+
self.config(),
84
+
output:.string(limit: limit),
85
+
error:.discarded
86
+
)
87
+
88
+
if !result.terminationStatus.isSuccess {
89
+
throwRunProgramError(terminationStatus: result.terminationStatus, config: c)
90
+
}
91
+
92
+
return result.standardOutput
93
+
}
94
+
}
95
+
96
+
publicfunc output(
97
+
environment:Environment=.inherit,
98
+
limit _:Int,
99
+
quiet:Bool=false,
100
+
body:(AsyncBufferSequence)->Void
101
+
)asyncthrows{
102
+
varc=self.config()
103
+
104
+
// TODO: someday the configuration might have its own environment from the modeled commands. That will require this to be able to merge the environment from the commands with the provided environment.
105
+
c.environment = environment
106
+
107
+
if !quiet {
108
+
letresult=tryawaitSubprocess.run(
109
+
self.config(),
110
+
error:.standardError
111
+
){ _, sequence in
112
+
body(sequence)
113
+
}
114
+
115
+
if !result.terminationStatus.isSuccess {
116
+
throwRunProgramError(terminationStatus: result.terminationStatus, config: c)
117
+
}
118
+
}else{
119
+
letresult=tryawaitSubprocess.run(
120
+
self.config(),
121
+
error:.discarded
122
+
){ _, sequence in
123
+
body(sequence)
124
+
}
125
+
126
+
if !result.terminationStatus.isSuccess {
127
+
throwRunProgramError(terminationStatus: result.terminationStatus, config: c)
0 commit comments