Skip to content

Commit 471ac6b

Browse files
committed
builtin: add Os.Env
1 parent 6e2596f commit 471ac6b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/par/builtin/Builtin.par

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ dec Os.TraverseDir : [Os.Path] Result<Os.Error, recursive either {
308308
.dir(Os.Path, self) self,
309309
}>
310310

311+
dec Os.Env : List<(Bytes) Bytes>
311312

312313
/// Url
313314

src/par/builtin/os.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ pub fn external_module() -> Module<std::sync::Arc<process::Expression<()>>> {
156156
),
157157
|handle| Box::pin(os_traverse_dir(handle)),
158158
),
159+
Definition::external(
160+
"Env",
161+
Type::name(
162+
Some("List"),
163+
"List",
164+
vec![Type::pair(Type::bytes(), Type::bytes())],
165+
),
166+
|handle| Box::pin(os_env(handle)),
167+
),
159168
],
160169
}
161170
}
@@ -565,6 +574,17 @@ async fn os_traverse_dir(mut handle: Handle) {
565574
}
566575
}
567576

577+
async fn os_env(mut handle: Handle) {
578+
for (name, value) in std::env::vars_os() {
579+
handle.signal(literal!("item"));
580+
let mut pair = handle.send();
581+
pair.send().provide_bytes(os_to_bytes(&name));
582+
pair.provide_bytes(os_to_bytes(&value));
583+
}
584+
handle.signal(literal!("end"));
585+
handle.break_();
586+
}
587+
568588
async fn pathbuf_from_os_path(mut handle: Handle) -> PathBuf {
569589
handle.signal(literal!("absolute"));
570590
let path_bytes = handle.bytes().await;

0 commit comments

Comments
 (0)