Skip to content

Commit bb63ee6

Browse files
authored
feat(jvm,native): Special-case "/dev/stdin" and "-" in TLAs, extVars, top-level file. (#449)
See #448. The /dev/stdin case is a work-around until scala-native/scala-native#4384 is fixed.
1 parent 65be8ac commit bb63ee6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sjsonnet/src-jvm-native/sjsonnet/SjsonnetMainBase.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,19 @@ object SjsonnetMainBase {
203203

204204
def splitMap(s: Seq[String], f: String => String) =
205205
s.map(split).map { case (x, v) => (x, f(v)) }
206-
def readPath(v: String) = os.read(os.Path(v, wd))
206+
def readPath(v: String) =
207+
if (v == "-" || v == "/dev/stdin") io.Source.stdin.mkString else os.read(os.Path(v, wd))
207208

208209
Map() ++
209210
splitMap(strs, v => ujson.write(v)) ++
210211
splitMap(strFiles, v => ujson.write(readPath(v))) ++
211212
splitMap(codes, identity) ++
212-
splitMap(codeFiles, v => s"import @'${v.replace("'", "''")}'")
213+
splitMap(
214+
codeFiles,
215+
v =>
216+
if (v == "-" || v == "/dev/stdin") io.Source.stdin.mkString
217+
else s"import @'${v.replace("'", "''")}'"
218+
)
213219
}
214220

215221
/**
@@ -229,6 +235,10 @@ object SjsonnetMainBase {
229235

230236
val (jsonnetCode, path) =
231237
if (config.exec.value) (file, wd / Util.wrapInLessThanGreaterThan("exec"))
238+
// TODO: Get rid of the /dev/stdin special-casing (everywhere!) once we use scala-native
239+
// with https://github.com/scala-native/scala-native/issues/4384 fixed.
240+
else if (file == "-" || file == "/dev/stdin")
241+
(io.Source.stdin.mkString, wd / Util.wrapInLessThanGreaterThan("<stdin>"))
232242
else {
233243
val p = os.Path(file, wd)
234244
(os.read(p), p)

0 commit comments

Comments
 (0)