feat: add example scripts for argparse, bytes, dataset, html, markdown, uuid, wdantic, and web chat modules

Add comprehensive demo scripts showcasing the usage of multiple Wren modules including argument parsing, byte manipulation, in-memory dataset operations, HTML encoding/slugification, markdown-to-HTML conversion, UUID generation/validation, schema validation with wdantic, and a full web chat application with REST endpoints.
This commit is contained in:
2026-01-24 22:40:22 +00:00
parent 0a65272f80
commit 5a4054ec66
105 changed files with 23275 additions and 94 deletions
+297
View File
@@ -0,0 +1,297 @@
<!DOCTYPE html>
<!-- retoor <retoor@molodetz.nl> -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>env - Wren-CLI Manual</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<button class="mobile-menu-toggle">Menu</button>
<div class="container">
<aside class="sidebar">
<div class="sidebar-header">
<h1><a href="../index.html">Wren-CLI</a></h1>
<div class="version">v0.4.0</div>
</div>
<nav class="sidebar-nav">
<div class="section">
<span class="section-title">Getting Started</span>
<ul>
<li><a href="../getting-started/index.html">Overview</a></li>
<li><a href="../getting-started/installation.html">Installation</a></li>
<li><a href="../getting-started/first-script.html">First Script</a></li>
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">Language</span>
<ul>
<li><a href="../language/index.html">Syntax Overview</a></li>
<li><a href="../language/classes.html">Classes</a></li>
<li><a href="../language/methods.html">Methods</a></li>
<li><a href="../language/control-flow.html">Control Flow</a></li>
<li><a href="../language/fibers.html">Fibers</a></li>
<li><a href="../language/modules.html">Modules</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">API Reference</span>
<ul>
<li><a href="index.html">Overview</a></li>
<li><a href="http.html">http</a></li>
<li><a href="websocket.html">websocket</a></li>
<li><a href="tls.html">tls</a></li>
<li><a href="net.html">net</a></li>
<li><a href="dns.html">dns</a></li>
<li><a href="json.html">json</a></li>
<li><a href="base64.html">base64</a></li>
<li><a href="regex.html">regex</a></li>
<li><a href="jinja.html">jinja</a></li>
<li><a href="crypto.html">crypto</a></li>
<li><a href="os.html">os</a></li>
<li><a href="env.html" class="active">env</a></li>
<li><a href="signal.html">signal</a></li>
<li><a href="subprocess.html">subprocess</a></li>
<li><a href="sqlite.html">sqlite</a></li>
<li><a href="datetime.html">datetime</a></li>
<li><a href="timer.html">timer</a></li>
<li><a href="io.html">io</a></li>
<li><a href="scheduler.html">scheduler</a></li>
<li><a href="math.html">math</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">Tutorials</span>
<ul>
<li><a href="../tutorials/index.html">Tutorial List</a></li>
</ul>
</div>
<div class="section">
<span class="section-title">How-To Guides</span>
<ul>
<li><a href="../howto/index.html">How-To List</a></li>
</ul>
</div>
</nav>
</aside>
<main class="content">
<nav class="breadcrumb">
<a href="../index.html">Home</a>
<span class="separator">/</span>
<a href="index.html">API Reference</a>
<span class="separator">/</span>
<span>env</span>
</nav>
<article>
<h1>env</h1>
<p>The <code>env</code> module provides access to environment variables for reading, writing, and deleting values.</p>
<pre><code>import "env" for Environment</code></pre>
<h2>Environment Class</h2>
<div class="class-header">
<h3>Environment</h3>
<p>Environment variable access</p>
</div>
<h3>Static Methods</h3>
<div class="method-signature">
<span class="method-name">Environment.get</span>(<span class="param">name</span>) &#8594; <span class="type">String|null</span>
</div>
<p>Gets the value of an environment variable.</p>
<ul class="param-list">
<li><span class="param-name">name</span> <span class="param-type">(String)</span> - Name of the environment variable</li>
<li><span class="returns">Returns:</span> Value of the variable, or null if not set</li>
</ul>
<pre><code>var home = Environment.get("HOME")
System.print(home) // /home/alice
var missing = Environment.get("UNDEFINED_VAR")
System.print(missing) // null</code></pre>
<div class="method-signature">
<span class="method-name">Environment.set</span>(<span class="param">name</span>, <span class="param">value</span>)
</div>
<p>Sets an environment variable.</p>
<ul class="param-list">
<li><span class="param-name">name</span> <span class="param-type">(String)</span> - Name of the environment variable</li>
<li><span class="param-name">value</span> <span class="param-type">(String)</span> - Value to set</li>
</ul>
<pre><code>Environment.set("MY_APP_DEBUG", "true")
System.print(Environment.get("MY_APP_DEBUG")) // true</code></pre>
<div class="method-signature">
<span class="method-name">Environment.delete</span>(<span class="param">name</span>)
</div>
<p>Deletes an environment variable.</p>
<ul class="param-list">
<li><span class="param-name">name</span> <span class="param-type">(String)</span> - Name of the environment variable to delete</li>
</ul>
<pre><code>Environment.delete("MY_APP_DEBUG")
System.print(Environment.get("MY_APP_DEBUG")) // null</code></pre>
<h3>Static Properties</h3>
<div class="method-signature">
<span class="method-name">Environment.all</span> &#8594; <span class="type">Map</span>
</div>
<p>Returns a map of all environment variables.</p>
<pre><code>var env = Environment.all
for (entry in env) {
System.print("%(entry.key) = %(entry.value)")
}</code></pre>
<h2>Examples</h2>
<h3>Reading Configuration from Environment</h3>
<pre><code>import "env" for Environment
var host = Environment.get("APP_HOST")
if (host == null) host = "localhost"
var port = Environment.get("APP_PORT")
if (port == null) port = "8080"
var debug = Environment.get("APP_DEBUG") == "true"
System.print("Starting server on %(host):%(port)")
System.print("Debug mode: %(debug)")</code></pre>
<h3>Default Values Pattern</h3>
<pre><code>import "env" for Environment
class Config {
static get(name, defaultValue) {
var value = Environment.get(name)
return value != null ? value : defaultValue
}
static getInt(name, defaultValue) {
var value = Environment.get(name)
if (value == null) return defaultValue
return Num.fromString(value)
}
static getBool(name, defaultValue) {
var value = Environment.get(name)
if (value == null) return defaultValue
return value == "true" || value == "1"
}
}
var timeout = Config.getInt("TIMEOUT", 30)
var verbose = Config.getBool("VERBOSE", false)
var logFile = Config.get("LOG_FILE", "/var/log/app.log")
System.print("Timeout: %(timeout)s")
System.print("Verbose: %(verbose)")
System.print("Log file: %(logFile)")</code></pre>
<h3>Setting Environment for Subprocesses</h3>
<pre><code>import "env" for Environment
import "subprocess" for Subprocess
Environment.set("NODE_ENV", "production")
Environment.set("PORT", "3000")
var result = Subprocess.run("node server.js")
System.print(result.stdout)</code></pre>
<h3>Listing All Environment Variables</h3>
<pre><code>import "env" for Environment
System.print("=== Environment Variables ===")
var env = Environment.all
var keys = []
for (entry in env) {
keys.add(entry.key)
}
keys.sort()
for (key in keys) {
System.print("%(key) = %(env[key])")</code></pre>
<h3>Checking Required Environment Variables</h3>
<pre><code>import "env" for Environment
var required = ["DATABASE_URL", "API_KEY", "SECRET_KEY"]
var missing = []
for (name in required) {
if (Environment.get(name) == null) {
missing.add(name)
}
}
if (missing.count > 0) {
System.print("Missing required environment variables:")
for (name in missing) {
System.print(" - %(name)")
}
Fiber.abort("Configuration error")
}
System.print("All required environment variables are set")</code></pre>
<h3>Temporary Environment Modification</h3>
<pre><code>import "env" for Environment
var originalPath = Environment.get("PATH")
Environment.set("PATH", "/custom/bin:" + originalPath)
System.print("Modified PATH for operations...")
Environment.set("PATH", originalPath)
System.print("Restored original PATH")</code></pre>
<h3>Database Connection String from Environment</h3>
<pre><code>import "env" for Environment
var dbUrl = Environment.get("DATABASE_URL")
if (dbUrl != null) {
System.print("Using database: %(dbUrl)")
} else {
var host = Environment.get("DB_HOST")
if (host == null) host = "localhost"
var port = Environment.get("DB_PORT")
if (port == null) port = "5432"
var name = Environment.get("DB_NAME")
if (name == null) name = "myapp"
var user = Environment.get("DB_USER")
if (user == null) user = "postgres"
dbUrl = "postgres://%(user)@%(host):%(port)/%(name)"
System.print("Constructed database URL: %(dbUrl)")
}</code></pre>
<div class="admonition note">
<div class="admonition-title">Note</div>
<p>Environment variables modified with <code>set</code> or <code>delete</code> only affect the current process and any child processes. They do not modify the parent shell's environment.</p>
</div>
<div class="admonition tip">
<div class="admonition-title">Tip</div>
<p>For configuration that may vary between environments (development, staging, production), use environment variables. This follows the twelve-factor app methodology.</p>
</div>
<div class="admonition warning">
<div class="admonition-title">Warning</div>
<p>Never log or print sensitive environment variables like API keys, passwords, or secrets. Use them directly in your application without exposing their values.</p>
</div>
</article>
<footer class="page-footer">
<a href="os.html" class="prev">os</a>
<a href="signal.html" class="next">signal</a>
</footer>
</main>
</div>
<script src="../js/main.js"></script>
</body>
</html>