Fix GenericOS.getenv returning a raw str, return an Option.t[str] instead.
This commit is contained in:
parent
e2f7f11d47
commit
0f23bbac01
3 changed files with 19 additions and 5 deletions
|
@ -23,9 +23,18 @@ fn expand_syntax_ext(parser.parser p,
|
|||
p.err("malformed #env call");
|
||||
}
|
||||
|
||||
// FIXME: if this was more thorough it would manufacture an
|
||||
// Option.t[str] rather than just an maybe-empty string.
|
||||
|
||||
auto var = expr_to_str(p, args.(0));
|
||||
auto val = GenericOS.getenv(var);
|
||||
ret make_new_str(sp, val);
|
||||
alt (GenericOS.getenv(var)) {
|
||||
case (Option.none[str]) {
|
||||
ret make_new_str(sp, "");
|
||||
}
|
||||
case (Option.some[str](?s)) {
|
||||
ret make_new_str(sp, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: duplicate code copied from extfmt.
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
fn getenv(str n) -> str {
|
||||
ret Str.str_from_cstr(OS.libc.getenv(Str.buf(n)));
|
||||
fn getenv(str n) -> Option.t[str] {
|
||||
auto s = OS.libc.getenv(Str.buf(n));
|
||||
if (s == 0 as Str.sbuf) {
|
||||
ret Option.none[str];
|
||||
} else {
|
||||
ret Option.some[str](Str.str_from_cstr(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ fn reset(IO.buf_writer writer) {
|
|||
}
|
||||
|
||||
fn color_supported() -> bool {
|
||||
ret Str.eq(GenericOS.getenv("TERM"), "xterm-color");
|
||||
ret GenericOS.getenv("TERM") == Option.some[str]("xterm-color");
|
||||
}
|
||||
|
||||
fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {
|
||||
|
|
Loading…
Reference in a new issue