Skip to content

add daslib/clargs#2454

Merged
borisbat merged 1 commit intoGaijinEntertainment:masterfrom
quasilyte:quasilyte_clargs
Apr 25, 2026
Merged

add daslib/clargs#2454
borisbat merged 1 commit intoGaijinEntertainment:masterfrom
quasilyte:quasilyte_clargs

Conversation

@quasilyte
Copy link
Copy Markdown
Contributor

Adds a command-line arguments handling library.
Also changes dastest das files
to use this new library.

Fixes #2316

@quasilyte quasilyte force-pushed the quasilyte_clargs branch 2 times, most recently from d950876 to bfb6c31 Compare April 21, 2026 21:18
@quasilyte
Copy link
Copy Markdown
Contributor Author

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.
I may try updating my local c++ compiler tomorrow.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.das with a [CommandLineArgs] structure macro that generates parse_args and get_command_info.
  • Adds dastest/dastest_clargs.das defining a DastestArgs schema (docs + flag naming) for dastest.
  • Updates dastest code to consume DastestArgs instead of manually scanning get_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.

Comment thread tests/daslib/clargs_test.das
Comment thread dastest/dastest.das
Comment thread daslib/clargs.das
Comment thread daslib/clargs.das Outdated
Comment thread dastest/dastest.das
Comment thread daslib/clargs.das Outdated
Comment thread daslib/clargs.das Outdated
Comment thread dastest/dastest_clargs.das
Comment thread dastest/dastest.das
Comment thread dastest/dastest.das
Comment thread dastest/dastest.das
// 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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread daslib/clargs.das
Comment thread daslib/clargs.das
Comment thread daslib/clargs.das
@aleksisch
Copy link
Copy Markdown
Collaborator

Thanks! Maybe we should replace all calls to get_command_line_arguments with clargs all over codebase (including das-fmt)? In separate commit / separate PR.

@quasilyte quasilyte force-pushed the quasilyte_clargs branch 3 times, most recently from e130000 to 5184092 Compare April 22, 2026 22:00
@quasilyte
Copy link
Copy Markdown
Contributor Author

Added clargs_required as requested by @aleksisch

@quasilyte quasilyte force-pushed the quasilyte_clargs branch 3 times, most recently from e094db4 to d151b3f Compare April 22, 2026 23:34
@borisbat borisbat assigned borisbat and unassigned borisbat Apr 23, 2026
@borisbat borisbat self-requested a review April 23, 2026 18:50
Copy link
Copy Markdown
Collaborator

@borisbat borisbat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing is language tutorial. this is one of the fundamental bits in daslang - so needs that.

@quasilyte quasilyte force-pushed the quasilyte_clargs branch 2 times, most recently from 383307d to 780c776 Compare April 23, 2026 21:06
@quasilyte quasilyte force-pushed the quasilyte_clargs branch 4 times, most recently from 831e9ac to 4b3d3f3 Compare April 24, 2026 19:14
Adds a command-line arguments handling library.
Also changes dastest das files
to use this new library.

Fixes GaijinEntertainment#2316
@borisbat borisbat merged commit 960986c into GaijinEntertainment:master Apr 25, 2026
26 checks passed
borisbat added a commit that referenced this pull request Apr 25, 2026
…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>
borisbat added a commit that referenced this pull request Apr 25, 2026
…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>
borisbat added a commit that referenced this pull request Apr 25, 2026
…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>
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.

Add command line arguments module

4 participants