@@ -35,9 +35,14 @@ private func withTemporaryFile<T>(contents: [UInt8], body: (URL) throws -> T) th
35
35
return try body ( tempFileURL)
36
36
}
37
37
38
- private func getContentsOfSourceFile( at path: String ) throws -> [ UInt8 ] {
39
- let sourceURL = URL ( fileURLWithPath: path)
40
- let source = try Data ( contentsOf: sourceURL)
38
+ private func getContentsOfSourceFile( at path: String ? ) throws -> [ UInt8 ] {
39
+ let source : Data
40
+ if let path = path {
41
+ let sourceURL = URL ( fileURLWithPath: path)
42
+ source = try Data ( contentsOf: sourceURL)
43
+ } else {
44
+ source = FileHandle . standardInput. readDataToEndOfFile ( )
45
+ }
41
46
return [ UInt8] ( source)
42
47
}
43
48
@@ -54,14 +59,14 @@ class SwiftParserTest: ParsableCommand {
54
59
class VerifyRoundTrip : ParsableCommand {
55
60
required init ( ) { }
56
61
57
- init ( sourceFile: String , swiftVersion: String ? , enableBareSlashRegex: Bool ? ) {
62
+ init ( sourceFile: String ? , swiftVersion: String ? , enableBareSlashRegex: Bool ? ) {
58
63
self . sourceFile = sourceFile
59
64
self . swiftVersion = swiftVersion
60
65
self . enableBareSlashRegex = enableBareSlashRegex
61
66
}
62
67
63
- @Argument ( help: " The source file that should be parsed " )
64
- var sourceFile : String
68
+ @Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
69
+ var sourceFile : String ?
65
70
66
71
@Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
67
72
var swiftVersion : String ?
@@ -109,8 +114,8 @@ class VerifyRoundTrip: ParsableCommand {
109
114
class PrintDiags : ParsableCommand {
110
115
required init ( ) { }
111
116
112
- @Argument ( help: " The source file that should be parsed " )
113
- var sourceFile : String
117
+ @Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
118
+ var sourceFile : String ?
114
119
115
120
@Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
116
121
var swiftVersion : String ?
@@ -141,8 +146,8 @@ class PrintDiags: ParsableCommand {
141
146
class DumpTree : ParsableCommand {
142
147
required init ( ) { }
143
148
144
- @Argument ( help: " The source file that should be parsed " )
145
- var sourceFile : String
149
+ @Argument ( help: " The source file that should be parsed; if omitted, use stdin " )
150
+ var sourceFile : String ?
146
151
147
152
@Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
148
153
var swiftVersion : String ?
@@ -167,8 +172,8 @@ class DumpTree: ParsableCommand {
167
172
class Reduce : ParsableCommand {
168
173
required init ( ) { }
169
174
170
- @Argument ( help: " The test case that should be reduced " )
171
- var sourceFile : String
175
+ @Argument ( help: " The test case that should be reduced; if omitted, use stdin " )
176
+ var sourceFile : String ?
172
177
173
178
@Option ( name: . long, help: " Interpret input according to a specific Swift language version number " )
174
179
var swiftVersion : String ?
0 commit comments