Skip to content

Add cxxopts long flags to nec_parse - #114

Merged
tmolteno merged 1 commit into
masterfrom
antlr-cxxopts-cli
Jul 17, 2026
Merged

Add cxxopts long flags to nec_parse#114
tmolteno merged 1 commit into
masterfrom
antlr-cxxopts-cli

Conversation

@tmolteno

Copy link
Copy Markdown
Owner

Summary

Replaced the bare argv[1] positional handling in nec_parse with cxxopts — a single-header MIT-licensed C++17 option parser (vendored as antlr/cxxopts.hpp v3.3.1). The header is picked up via the existing -I . include path, so there is no Dockerfile or build_in_docker.sh change.

New options

Long Short Behavior
--input <file> -i Input NEC file; reads stdin if omitted (fallback preserved)
--output <file> -o Output file for the NEC simulation log; stdout if omitted. Structured summary always goes to stdout (matches nec2++)
--benchmark -b Runs nec_context::benchmark() and exits
--version -v Prints nec_parse <version>
--help -h Auto-generated usage (by cxxopts)

The --output FILE* is owned by a unique_ptr with an fclose deleter so it is closed cleanly on every return path. Bad flags produce a clean error message + help text and exit 1 (no uncaught exception).

Why cxxopts (vendored)

  • Single MIT-licensed header → GPLv3-compatible, no build-system complexity.
  • Vendoring (vs. apt libcxxopts-dev) keeps the antlr Docker side-build self-contained, no new apt dependency, pinned reproducible version.
  • Auto-generates --help, supports long+short flags together.

Files changed

  • antlr/cxxopts.hppnew, vendored v3.3.1 (2930 lines)
  • antlr/nec_test.cpp — cxxopts parse block, --output wired into s_output.set_file()
  • antlr/Makefile — "CLI options (cxxopts)" smoke checks in test:

Verification (all pass)

  • --help / -h → usage, exit 0
  • --versionnec_parse 2.1.1 [2026-07-18], exit 0
  • --benchmark → prints NEC score, exit 0
  • --input <file> → full simulation to stdout (unchanged output)
  • stdin fallback (no --input) → works
  • --output <file> → writes the 182-line simulation log to file
  • --bogus → clean error + exit 1
  • Build is warning-free; full make test green.

⚠️ Breaking change

Callers using the bare positional form nec_parse <file> must now use nec_parse --input <file> (or -i). The PR #113 simulation behavior is otherwise unchanged.

…ark)

Replaced the bare argv[1] positional handling in nec_parse with cxxopts,
a single-header MIT-licensed C++17 option parser (vendored as
antlr/cxxopts.hpp v3.3.1, picked up via the existing -I . include path;
no Dockerfile or build_in_docker.sh change).

New options:
  -i, --input <file>    input NEC file (reads stdin if omitted)
  -o, --output <file>   output file for the NEC simulation log
                         (stdout if omitted); the structured summary
                         still goes to stdout, matching nec2++
  -b, --benchmark       run nec_context::benchmark() and exit
  -v, --version         print version and exit
  -h, --help            auto-generated usage (by cxxopts)

The --output FILE* is owned by a unique_ptr with an fclose deleter so it
is closed on every return path. Bad flags produce a clean error + help
text and exit 1 rather than an uncaught exception.

Added a 'CLI options (cxxopts)' block to antlr/Makefile test: asserting
--help lists --input/--benchmark and --benchmark prints a score. Full
make test is green.

NOTE: this is a breaking change for callers using the bare positional
form 'nec_parse <file>'; they must now use 'nec_parse --input <file>'.
@tmolteno
tmolteno merged commit ade4879 into master Jul 17, 2026
1 check passed
@tmolteno
tmolteno deleted the antlr-cxxopts-cli branch July 17, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant