✓
Passing This code compiles and runs correctly.
Code
// Pins that a [comptime|command] handler observes build:config values.
//
// Command handlers dispatch via koru_command_dispatch, which returns before
// the pipeline's comptime passes — the passes that register build:config /
// build:variants into emitter_helpers. Dispatch primes comptime_main before
// invoking a handler, so this handler reads a populated registry.
//
// Run: koruc input.kz cfg --build=dev → port=3000
// koruc input.kz cfg --build=prod → port=80
~import std/build
~import std/compiler
~[build("dev")]std/build:config {
"port": "3000"
}
~[build("prod")]std/build:config {
"port": "80"
}
~std/compiler:command.declare {
"name": "cfg",
"description": "Print the build:config port the handler observes"
}
~[comptime|command]pub tor cfg {
program: *const Program,
allocator: __koru_std.mem.Allocator,
argv: []string,
}
const std = @import("std");
~proc cfg|zig {
const emitter_helpers = @import("emitter_helpers");
if (emitter_helpers.getBuildConfig("port")) |v| {
std.debug.print("port={s}\n", .{v});
} else {
std.debug.print("port=MISSING\n", .{});
}
}
~tor main {}
~proc main|zig {
}
~main()
Flows
flow ~config click a branch to expand · @labels scroll to their anchor
config (source: "port": "3000")
flow ~config click a branch to expand · @labels scroll to their anchor
config (source: "port": "80")
flow ~command.declare click a branch to expand · @labels scroll to their anchor
command.declare (source: "name": "cfg",
"description": "Print the build:config port the handler observes")
flow ~main click a branch to expand · @labels scroll to their anchor
main
Test Configuration
Post-validation Script:
#!/bin/bash
# The handler must observe the flag-gated build:config value, not an empty
# registry. `port=MISSING` under either build flag is the failure this pins.
set -e
DEV=$(koruc "$KORU_INPUT" cfg --build=dev 2>&1)
echo "$DEV" | grep -q "port=3000" || { echo "FAIL: dev did not resolve port=3000"; echo "$DEV"; exit 1; }
PROD=$(koruc "$KORU_INPUT" cfg --build=prod 2>&1)
echo "$PROD" | grep -q "port=80" || { echo "FAIL: prod did not resolve port=80"; echo "$PROD"; exit 1; }