Issue #2639: Struct options of main are flattened on the command line, with field docs in the help (ADR-cli-v1 D8)

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 #2637 (move std::cli into Nikaia): the runtime this changes is cli.nika from there.

Decision: ADR-cli-v1 D8, D5 (help of a struct option), and the main-only part of D11 (NK1357 inside main); Part I 5.5.

Probe

struct Global {
    /// Prints each step.
    verbose: bool = false,
}

fn main(file: String; global: Global = Global {}) {
    println(f"{file} {global.verbose}")
}

Today:

error[NK1273]: `global` of `main` can't be a word on the command line: it is a `Global`.
  --> flat.nika:6:1

Expected

prog areas.md --verbose prints areas.md true; prog areas.md prints areas.md false. Each field of a struct option is a named argument of its own, by the field’s name (_ written -), with the field’s default, read as an option of that type is read today. --help lists --verbose under the option with the field’s /// lines. Refused while the program is built:

To build

  1. Check in crates/nikaia-std/src/compiler/check_main.nika (main_word_type, main_refused_type, main_option_word): accept a struct option whose default is the all-defaults literal and whose fields are words; NK1273 otherwise; NK1357 on a flattened name clash. Tests cli_struct_option_default_not_all_defaults.nika + .stderr, cli_struct_option_field_not_a_word.nika + .stderr, cli_struct_option_name_clash.nika + .stderr.
  2. Doc field: Param in cli.nika gets the /// lines of what it reads (doc), and help prints them; emit_entry.nika (main_words_of) fills it, empty for today’s parameters until step 3, so today’s help is unchanged. Test: the four cli_* tests stay byte for byte.
  3. Flatten in emit_entry.nika (main_words_of, main_claims_of): one Param per field, each read with __nikaia_words.option(at) or its default, then the struct built from them and passed as the option. Test cli_struct_option_is_flattened.nika + .stdout, in the form of cli_words_are_sorted_into_the_parameters.nika (writes a program to fs::scratch(), builds it, runs it with --verbose, without, with --verbose=false, and with -h, printing the output and the exit status).
  4. Part I 5.5 and Part III 30: NK1357’s row says which half is built (inside main); the rest comes with the Command issues.

Done when

The tests pass, every cli_* and main-words test stays green; step 4’s commit carries Fixes #N; gaps are Found: lines.

Files: check_main.nika, emit_entry.nika, crates/nikaia-std/src/cli.nika (and its lowered output), Part I 5.5, Part III 30, tests in tests/compiler/tests/. No new Rust.

Facts: nikaia test --filter cli_ from tests/compiler. The emitted Rust is visible in the project test cache (target/nikaia-project-tests).

Ruled out: a prefix for flattened names (--global-verbose; ADR-cli-v1 §3 weighed it); a nested struct inside a struct option (not decided: NK1273); flattening a struct subject (only options).

Back to Open Issues