Files
wren/example/argparse_demo.wren
T
retoor 5a4054ec66 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.
2026-01-24 22:40:22 +00:00

36 lines
1.4 KiB
JavaScript
Vendored

// retoor <retoor@molodetz.nl>
import "argparse" for ArgumentParser
System.print("=== Argparse Module Demo ===")
System.print("\n--- Basic Usage ---")
var parser = ArgumentParser.new("A sample program")
parser.prog = "sample"
parser.addArgument("input", {"help": "Input file"})
parser.addArgument("-o", {"long": "--output", "default": "output.txt", "help": "Output file"})
parser.addArgument("-v", {"long": "--verbose", "action": "storeTrue", "help": "Verbose output"})
parser.addArgument("-n", {"type": "int", "default": 1, "help": "Number of iterations"})
System.print("Help message:")
parser.printHelp()
System.print("\n--- Parsing Example Args ---")
var args = parser.parseArgs(["data.txt", "-v", "-n", "5", "--output", "result.txt"])
System.print("Input: %(args["input"])")
System.print("Output: %(args["output"])")
System.print("Verbose: %(args["verbose"])")
System.print("Iterations: %(args["n"])")
System.print("\n--- Count Action ---")
var parser2 = ArgumentParser.new()
parser2.addArgument("-v", {"action": "count"})
var args2 = parser2.parseArgs(["-v", "-v", "-v"])
System.print("Verbosity level: %(args2["v"])")
System.print("\n--- Append Action ---")
var parser3 = ArgumentParser.new()
parser3.addArgument("-i", {"long": "--include", "action": "append"})
var args3 = parser3.parseArgs(["-i", "module1", "-i", "module2", "--include", "module3"])
System.print("Included modules: %(args3["include"])")