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

PuduLangEnvironment.pudu

Pudu50 lines2.1 KB

GitHub ↗
1/** @Environment.Root.Vocabulary — problems a load or read reports */2module PuduLangEnvironment34import PuduLangEnvironment.Constants.Messages as Messages5import PuduLangEnvironment.Utils.Template as Template67/** @Environment.Root.Problem — why a load or read has no answer */8export type Problem9  = BlankPath10  | MissingFile(Str)11  | Unreadable(Str, Str)12  | Undecodable(Str, Str)13  | UnclosedQuote(Str, Int, Str)14  | NotFound(Array[Str])15  | UnsafeEnvironmentName(Str)16  | InvalidOptions(Array[Str])17  | Missing(Array[Str])18  | Malformed(Str, Str)19  | Invalid(Array[Str])2021/// One sentence saying what went wrong, naming keys, lines, and paths but never a value.22export fn describe(problem: &Problem) -> Str {23  match problem {24    case BlankPath => Messages.BLANK_PATH25    case MissingFile(path) => Template.fill(Messages.MISSING_FILE, &[path])26    case Unreadable(path, reason) => Template.fill(Messages.UNREADABLE, &[path, reason])27    case Undecodable(source, encoding) => Template.fill(Messages.UNDECODABLE, &[source, encoding])28    case UnclosedQuote(source, line, key) => Template.fill(Messages.UNCLOSED_QUOTE, &[source, show(line), key])29    case NotFound(paths) => Template.fill(Messages.NOT_FOUND, &[paths.join(Messages.LIST_SEPARATOR)])30    case UnsafeEnvironmentName(name) => Template.fill(Messages.UNSAFE_ENVIRONMENT_NAME, &[name])31    case InvalidOptions(problems) => Template.fill(Messages.INVALID_OPTIONS, &[problems.join(Messages.PROBLEM_SEPARATOR)])32    case Missing(keys) => Template.fill(Messages.MISSING, &[keys.join(Messages.LIST_SEPARATOR)])33    case Malformed(key, kind) => Template.fill(Messages.MALFORMED, &[key, kind])34    case Invalid(failures) => Template.fill(Messages.INVALID_SETTINGS, &[failures.join(Messages.LIST_SEPARATOR)])35  }36}3738/// Whether a lenient load may record the problem and go on: a source that is absent or cannot be39/// read, as opposed to one that is wrong.40export fn isSkippable(problem: &Problem) -> Bool {41  match problem {42    case BlankPath => true43    case MissingFile(_) => true44    case Unreadable(_, _) => true45    case Undecodable(_, _) => true46    case NotFound(_) => true47    case _ => false48  }49}50