add daslib/clargs#2454
Conversation
d950876 to
bfb6c31
Compare
|
There is something wrong after rebasing on master, but I can't compile the project locally yet after that rebase either, so it will take a bit more time to fix. |
There was a problem hiding this comment.
Pull request overview
Adds a new daslib/clargs macro-based command-line parsing utility and migrates dastest argument handling to use it, addressing the repeated ad-hoc parsing noted in #2316.
Changes:
- Introduces
daslib/clargs.daswith a[CommandLineArgs]structure macro that generatesparse_argsandget_command_info. - Adds
dastest/dastest_clargs.dasdefining aDastestArgsschema (docs + flag naming) fordastest. - Updates
dastestcode to consumeDastestArgsinstead of manually scanningget_command_line_arguments.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
daslib/clargs.das |
New CLI parsing + macro codegen (parse + command metadata). |
dastest/dastest_clargs.das |
Defines DastestArgs as the parsed schema for dastest flags. |
dastest/suite.das |
Switches SuiteCtx construction to accept DastestArgs instead of raw argv. |
dastest/dastest.das |
Migrates main to DastestArgs parsing and replaces several manual flag reads. |
tests/daslib/clargs_test.das |
Adds unit tests for the new clargs parsing behavior and command info output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // we can replace that too, just need to find the best plan. | ||
| var raw_args <- get_command_line_arguments() | ||
|
|
||
| // init_log uses daslib ansi-colors, which relies on array<string> parsing. |
There was a problem hiding this comment.
Maybe create config for arguments in daslib/ansi_colors.das and either pass it instead of array or pass nothing and call get_command_line_arguments again? Feel free to ignore.
|
Thanks! Maybe we should replace all calls to |
e130000 to
5184092
Compare
|
Added clargs_required as requested by @aleksisch |
e094db4 to
d151b3f
Compare
borisbat
left a comment
There was a problem hiding this comment.
missing is language tutorial. this is one of the fundamental bits in daslang - so needs that.
383307d to
780c776
Compare
831e9ac to
4b3d3f3
Compare
Adds a command-line arguments handling library. Also changes dastest das files to use this new library. Fixes GaijinEntertainment#2316
4b3d3f3 to
c74e6de
Compare
…ring> finders Follow-up to #2454. Adds the missing pieces of daslib/clargs: * @clarg_short = "X" — single-character short flags, all field types, with collision detection and single-char validation (compile-time errors from the macro). Mixed long+short occurrences of array flags preserve declaration order. * print_help / format_help — render Usage / Flags blocks from CommandInfo. Bool flags omit =PLACEHOLDER; enums render values inline; (required) and (repeated) markers in the doc column. format_help returns a string (testable, redirectable); print_help wraps it. parse_args does NOT auto-recognize --help — declare an explicit help : bool field and check it after parsing. * get_program_args() — companion to get_cli_arguments() for AOT'd standalone tools that own argv directly (no "--" separator). Both helpers ship a (argv) overload to make the splitting logic unit-testable without touching the live process state. * find_*_raw_value : Option<string> — replaces the tuple<string, bool> return shape with the freshly-merged Option type. Also fixes a pre-existing bug in collect_command_info: is_array was being driven by isVectorType() (float2/int4-style), so array<string> fields silently came out with is_array=false. Switched to the actual Type.tArray check + firstType lookup. dastest is migrated off the residual hand-rolled --run scan: parse_args already populates test_args.run from both --run X and --run=X forms, so the find_index("--run") + args[runIdx+1] dance is gone (also fixes the out-of-bounds when --run is the last token), and the "command-line args" error path returns 1 instead of fio::exit(1). Tutorial 53 + RST grow three new sections (short flags, help rendering, standalone-tool args) and the user-side print_help in the introspection section is replaced by a call to the library helper. das2rst's option / result Operators groups extended to also catch !=, removing the pre-existing Uncategorized sections in the generated docs. 34 clargs tests pass (15 original + 19 new). Full suite 6665/6665, AOT regression 6077/6077, no GC/handle/smart_ptr leaks. Sphinx clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ring> finders Follow-up to #2454. Adds the missing pieces of daslib/clargs: * @clarg_short = "X" — single-character short flags, all field types, with collision detection and single-char validation (compile-time errors from the macro). Mixed long+short occurrences of array flags preserve declaration order. * print_help / format_help — render Usage / Flags blocks from CommandInfo. Bool flags omit =PLACEHOLDER; enums render values inline; (required) and (repeated) markers in the doc column. format_help returns a string (testable, redirectable); print_help wraps it. parse_args does NOT auto-recognize --help — declare an explicit help : bool field and check it after parsing. * get_program_args() — companion to get_cli_arguments() for AOT'd standalone tools that own argv directly (no "--" separator). Both helpers ship a (argv) overload to make the splitting logic unit-testable without touching the live process state. * find_*_raw_value : Option<string> — replaces the tuple<string, bool> return shape with the freshly-merged Option type. Also fixes a pre-existing bug in collect_command_info: is_array was being driven by isVectorType() (float2/int4-style), so array<string> fields silently came out with is_array=false. Switched to the actual Type.tArray check + firstType lookup. dastest is migrated off the residual hand-rolled --run scan: parse_args already populates test_args.run from both --run X and --run=X forms, so the find_index("--run") + args[runIdx+1] dance is gone (also fixes the out-of-bounds when --run is the last token), and the "command-line args" error path returns 1 instead of fio::exit(1). Tutorial 53 + RST grow three new sections (short flags, help rendering, standalone-tool args) and the user-side print_help in the introspection section is replaced by a call to the library helper. das2rst's option / result Operators groups extended to also catch !=, removing the pre-existing Uncategorized sections in the generated docs. 34 clargs tests pass (15 original + 19 new). Full suite 6665/6665, AOT regression 6077/6077, no GC/handle/smart_ptr leaks. Sphinx clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ring> finders Follow-up to #2454. Adds the missing pieces of daslib/clargs: * @clarg_short = "X" — single-character short flags, all field types, with collision detection and single-char validation (compile-time errors from the macro). Mixed long+short occurrences of array flags preserve declaration order. * print_help / format_help — render Usage / Flags blocks from CommandInfo. Bool flags omit =PLACEHOLDER; enums render values inline; (required) and (repeated) markers in the doc column. format_help returns a string (testable, redirectable); print_help wraps it. parse_args does NOT auto-recognize --help — declare an explicit help : bool field and check it after parsing. * get_program_args() — companion to get_cli_arguments() for AOT'd standalone tools that own argv directly (no "--" separator). Both helpers ship a (argv) overload to make the splitting logic unit-testable without touching the live process state. * find_*_raw_value : Option<string> — replaces the tuple<string, bool> return shape with the freshly-merged Option type. Also fixes a pre-existing bug in collect_command_info: is_array was being driven by isVectorType() (float2/int4-style), so array<string> fields silently came out with is_array=false. Switched to the actual Type.tArray check + firstType lookup. dastest is migrated off the residual hand-rolled --run scan: parse_args already populates test_args.run from both --run X and --run=X forms, so the find_index("--run") + args[runIdx+1] dance is gone (also fixes the out-of-bounds when --run is the last token), and the "command-line args" error path returns 1 instead of fio::exit(1). Tutorial 53 + RST grow three new sections (short flags, help rendering, standalone-tool args) and the user-side print_help in the introspection section is replaced by a call to the library helper. das2rst's option / result Operators groups extended to also catch !=, removing the pre-existing Uncategorized sections in the generated docs. 34 clargs tests pass (15 original + 19 new). Full suite 6665/6665, AOT regression 6077/6077, no GC/handle/smart_ptr leaks. Sphinx clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a command-line arguments handling library.
Also changes dastest das files
to use this new library.
Fixes #2316