Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-environment

Environment files for Pudu: load .env variables safely with layered files, discovery, expansion, typed reads, and secrets kept out of every message

0.1.0Apache-2.01

InstallClose

InMemory.pudu

Pudu25 lines1.1 KB

GitHub ↗
1/** @Examples.InMemory.Program — sources, expansion, and defaults without files */2module InMemory34import Std.Bytes as Bytes5import Std.Io as Io6import Std.Map as Map7import PuduLangEnvironment.Domain.Encoding as Encoding8import PuduLangEnvironment.Loader as Loader9import PuduLangEnvironment.Options as Options10import PuduLangEnvironment.Source as Source1112/// Reads text and Latin-1 bytes as two layers, expanding references with fallbacks.13fn main() -> Int {14  let shared = Source.Text("shared", "export REGION=eu-west\nBUCKET=assets-$REGION # where uploads go\n")15  let local = Source.Data("local", Bytes.fromText("CITY='Mal' \nBANNER=\"$\{GREETING:-Hello\} from $BUCKET\"\n"))16  let options = Options.defaults().withSources(&[shared, local]).withExportSyntax().withExpansion().withTrimValues().withEncoding(Encoding.Latin1)17  match Loader.readOver(&options, &Map.empty()) {18    case Ok(values) => {19      for pair in values.entries() { let _shown = Io.writeLine(pair[0] + "=" + pair[1]) }20      if values.get("BANNER") == Some("Hello from assets-eu-west") && values.get("CITY") == Some("Mal") { 0 } else { 1 }21    }22    case Err(_) => 123  }24}25