src/bin/weaveback-macro.rs is the weaveback-macro command-line binary.
It wraps the macro_api layer with a clap argument
parser, adds --dir discovery mode, and exposes --dump-ast for debugging.
Design rationale
--dir discovery mode
When --dir is given, the binary:
-
Recursively collects all files matching
--extunder the directory. -
Runs a discovery pass — a second evaluation in
discovery_mode: truewhere%include(path)calls are recorded but not expanded. -
Filters out any file that appears as a
%includetarget of another file in the same scan, leaving only driver files (top-level entry points). -
Processes the driver files with a fresh evaluator.
This means you can drop all your literate fragments and their driver into one
directory and run weaveback-macro --dir . without manually listing which file
is the entry point.
Mutual exclusion: positional inputs vs --dir
ArgGroup::new("source").required(true) enforces that exactly one of
--dir or positional input files is present. The conflicts_with = "inputs"
attribute on --dir is the clap-level guard; the run() function branches on
args.directory.
--pathsep and platform defaults
On Unix the path separator for --include is :, on Windows ;.
default_pathsep() returns the right one for the current target triple at
compile time so the binary behaves correctly without user configuration.
--dump-ast
Skips evaluation entirely and serialises the parsed AST of each input file to
<file>.ast. Useful for debugging macro parse errors.
File structure
// <<@file weaveback-macro/src/bin/weaveback-macro.rs>>=
// <<cli preamble>>
// <<cli default pathsep>>
// <<cli find files>>
// <<cli args struct>>
// <<cli run>>
// <<cli main>>
// @
Preamble
// <<cli preamble>>=
// crates/weaveback-macro/src/bin/macro_cli.rs
use ;
use process_string;
use ;
use HashSet;
use ;
// @
Platform path separator
// <<cli default pathsep>>=
/// Returns the default path separator based on the platform
// @
find_files — recursive extension scanner
// <<cli find files>>=
/// Recursively collect all files whose extension matches any entry in `exts` under `dir`.
// @
CLI argument struct
// <<cli args struct>>=
// @
run — core logic
// <<cli run>>=
// @
main
// <<cli main>>=
// @
Tests
Integration tests for the weaveback-macro CLI binary. They use escargot to
build and invoke the binary as a subprocess, exercising the full CLI contract:
-
test_basic_macro_processing—%def/ invocation round-trip to output file -
test_cli_help—--helpexits 0 and mentionsweaveback-macro/--output -
test_missing_input_file— non-existent input → non-zero exit + error message -
test_multiple_inputs— two input files concatenated into one output -
test_custom_special_char—--special @selects@as macro sigil -
test_rhaidef_arithmetic—%rhaidefwith Rhai expression body computes 21*2 -
test_colon_separated_includes—--include ./pathcolon syntax resolves files -
test_custom_pathsep_includes—--pathsep |overrides the include separator -
test_large_input— 10 000-line file with 10 000 macro expansions (smoke test)
// <<@file weaveback-macro/tests/test_macro_cli.rs>>=
// crates/weaveback-macro/tests/test_macro_cli.rs
use escargot;
use fs;
use Write;
use ;
use TempDir;
// Helper function to create a file with content
// Helper to build and get command
// 1) Test the help message
// 2) Test passing a non-existent input file
// 3) Test multiple input files in a single run
// 4) Test a custom special char
// 5) Test rhaidef: arithmetic via Rhai scripting
// 6) Test using a colon-separated include path
// 7) Test forcing a custom --pathsep
// 8) Test that the CLI can handle a large input file (smoke test)
// @