Add cxxopts long flags to nec_parse - #114
Merged
Merged
Conversation
…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>'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaced the bare
argv[1]positional handling innec_parsewith cxxopts — a single-header MIT-licensed C++17 option parser (vendored asantlr/cxxopts.hppv3.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
--input <file>-i--output <file>-onec2++)--benchmark-bnec_context::benchmark()and exits--version-vnec_parse <version>--help-hThe
--outputFILE*is owned by aunique_ptrwith anfclosedeleter 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)
libcxxopts-dev) keeps the antlr Docker side-build self-contained, no new apt dependency, pinned reproducible version.--help, supports long+short flags together.Files changed
antlr/cxxopts.hpp— new, vendored v3.3.1 (2930 lines)antlr/nec_test.cpp— cxxopts parse block,--outputwired intos_output.set_file()antlr/Makefile— "CLI options (cxxopts)" smoke checks intest:Verification (all pass)
--help/-h→ usage, exit 0--version→nec_parse 2.1.1 [2026-07-18], exit 0--benchmark→ prints NEC score, exit 0--input <file>→ full simulation to stdout (unchanged output)--input) → works--output <file>→ writes the 182-line simulation log to file--bogus→ clean error + exit 1make testgreen.Callers using the bare positional form
nec_parse <file>must now usenec_parse --input <file>(or-i). The PR #113 simulation behavior is otherwise unchanged.