main and command help (ADR-cli-v1 D11, D12)Open and answer this issue on GitHub.
ready · opened 2026-11-21 · updated 2026-11-21 · 0 comments
Part of #449 (subcommands of main, option A).
After #2640 (Command[f, g] dispatch).
Decision: ADR-cli-v1 D11 and D12; Part I 5.5.
struct Global {
/// Prints each step.
verbose: bool = false,
}
/// Runs one step.
fn run_step(step: String; global: Global = Global {}) {
println(f"run {step} {global.verbose}")
}
/// Picks the next focus.
fn focus_next(file: String; global: Global = Global {}, depth: int = 1) {
println(f"focus {file} {depth} {global.verbose}")
}
fn main(command: Command[run_step, focus_next]; global: Global = Global {}) {
command.run(..command.args; ..command.options, global: global)
}
prog --verbose focus-next areas.md and prog focus-next areas.md --verbose both print focus areas.md 1 true: a name main declares is main’s, and reaches the function through the call’s written global: global. Leaving out global: global is NK1356 (reserved), whose help names the option. A function option that flattens to a name of main with another type is NK1357. prog --help prints the usage prog [OPTIONS] COMMAND …, main’s options, and each command by its command-line name with its first /// line; prog focus-next --help prints that function’s help (as D5) followed by main’s options.
check_core_args.nika or where #2640 checks command.run): every option shared by main and a picked function must be written beside the spread. Test cli_command_shared_option_left_out.nika + .stderr.main and a function (check_main.nika): same flattened name, other type. Test cli_command_option_clash_with_main.nika + .stderr.main’s options are read wherever they stand, before or after the command word, and a function’s own options only after it (cli.nika). Test cli_command_main_option_before_and_after.nika + .stdout.cli.nika usage / help, emit_entry.nika passing each function’s first /// line): test cli_command_help.nika + .stdout with --help, -h, focus-next --help, exit status 0.The tests pass, the cli_* tests stay green; step 5’s commit carries Fixes #N; gaps are Found: lines.
Files: check_core_args.nika, check_main.nika, emit_entry.nika, cli.nika, Part III 30, tests in tests/compiler/tests/. No new Rust.
Facts: nikaia test --filter cli_command from tests/compiler.
Ruled out: passing main’s shared option to the function silently (D11: a word given once is never dropped, and never passed without being written); a separate --help per option group.