1 # run/bend: which bend is on the PATH, asked the way that bend will answer. 2 # 3 # bend has had the question two ways round. Up to 2.0.16 it is `bend --version` 4 # and `bend version` is "no such file: version"; from 2.0.18 on it is `bend 5 # version` and the flag is "unknown option --version". Either way the spelling 6 # it does not know exits non-zero, which looks exactly like a bend that is not 7 # installed — so a caller that asks only one way cannot tell a missing bend 8 # from an old one, and ez has two callers that need the banner: doctor's 9 # report and the toolchain part of a cache key. 10 # Asking both ways, current spelling first, is the whole of this module. 11 import Base 12 import 0xabe575924687afad4cee1a2c1194d639/main.bend as R 13 14 # the older spelling, tried only when the current one was not understood 15 def version.older(ok: Bool, out: String) -> IO(String): 16 match ok: 17 case True{}: 18 IO.pure(String, out) 19 case False{}: 20 R.exec(["bend", "--version"]) 21 22 # `bend` asked which bend it is, as a run's answer: the status line, then the 23 # banner. A bend that is not on the PATH fails both spellings, so the status 24 # an absent bend answers with is still the one the caller sees. 25 def version() -> IO(String): 26 do IO: 27 +out : String <- R.exec(["bend", "version"]) 28 version.older(R.ok(out), out)