Skip to content

Refactor command-line arg parsing to use pre-sliced (argc, argv) views#89

Merged
thetic merged 7 commits into
mainfrom
cmd-args-consumed
Apr 25, 2026
Merged

Refactor command-line arg parsing to use pre-sliced (argc, argv) views#89
thetic merged 7 commits into
mainfrom
cmd-args-consumed

Conversation

@thetic
Copy link
Copy Markdown
Owner

@thetic thetic commented Apr 25, 2026

Description

Replaces the mutable int& index threading through the argument-parsing chain with explicit return values and pre-sliced argv views. Each helper now receives (int argc, const char* const* argv) where argv[0] is always the flag under inspection, eliminating position arithmetic inside helpers. JUnitOutputPlugin retains its original default package name (binary basename) by accepting it as a constructor parameter populated by CommandLineRunner.

Related Issues

Fixes # (issue number)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Breaking: Plugin::parse_arguments(int, const char* const*, int index)Plugin::parse_arguments(int, const char* const*). Subclasses must update their override signature and replace argv[index] with argv[0].

Manual Verification (Optional)

If you have verified this change on hardware or a simulator not covered by CI (e.g., a specific ARM target), please describe it here:

  • Target:
  • Result:

Checklist

  • I have written/updated documentation in docs/ for any user-facing changes.
  • My code follows the project's naming conventions (mu::tiny namespace, INCLUDED_MU_TINY_ guards, mutiny_ C-prefix).
  • For new features, I have considered if a C-interface adapter (.h and .c.cpp) is required for parity.
  • I have reviewed the CONTRIBUTING.md file to ensure compliance with architectural guidelines.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 25, 2026

Coverage Status

coverage: 98.926% (+0.02%) from 98.904% — cmd-args-consumed into main

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 25, 2026

TestsPassed ✅Skipped ⚠️Failed
JUnit Tests1064 ran1055 passed9 skipped0 failed

thetic added 6 commits April 24, 2026 20:02
…ng index

parse_prefix_arg and parse_argument now return int (-1 = unrecognised,
>=0 = extra args consumed) instead of bool with an int& index threaded
through the call chain. parse() advances its loop variable by the
return value.

Helpers (add_group_filter, set_repeat_count, etc.) now receive a
pre-sliced view (argc remaining, argv pointing at the current flag) so
they work with argv[0]/argv[1] directly and carry no knowledge of their
position in the global argument array. parse_prefix_arg is the single
site that computes ac_ - index / av_ + index.
parse_arguments() and parse_all_arguments() no longer take a global
index. Callers pass (remaining_argc, argv + current_pos) so that
argv[0] is always the argument under inspection — consistent with the
same convention now used throughout CommandLineArguments.

parse_prefix_arg() and parse_argument() follow suit: they now accept
(int argc, const char* const* argv, Plugin*) and argv[0] is the
current flag, eliminating the last index/argument-string parameters
from the internal parsing chain.

JUnitOutputPlugin no longer derives a package name from the binary
path (argv[0] in the old global array). Plain -pjunit leaves
package_name_ empty; -pjunit=<name> still sets it explicitly.
JUnitOutputPlugin now takes an optional default_package_name in its
constructor, used when -pjunit is given without an explicit =<name>
suffix. CommandLineRunner extracts the basename from argv[0] at
construction time and passes it to the plugin, restoring the original
behaviour where the executable name prefixes JUnit classnames.
- defaultPackageName_usedWhenNoPjunitSuffix: verifies that the
  constructor default is reflected in the XML classname and filename
  when -pjunit is given with no =<name> suffix
- defaultPackageName_overriddenByExplicitSuffix: verifies that an
  explicit -pjunit=name overrides a non-empty constructor default
- emptyDefaultPackageName_producesNoPrefix: verifies that an empty
  default (the no-arg constructor) produces no package prefix in the
  classname and writes to mutiny.xml
… API

- plugins.rst: remove int index from the parse_arguments signature in
  the code block; note that argv[0] is the argument to inspect
- junit-output.rst: update the manual installation example to show
  passing a default package name to the JUnitOutputPlugin constructor;
  document the three-tier fallback for the output filename
@thetic thetic force-pushed the cmd-args-consumed branch from a24b2bb to 5206cc8 Compare April 25, 2026 03:03
…traction

Cover get_parameter_field's empty-fallback path (flag with no inline value
and no following token) and basename_from_path's null/empty guard.
@thetic thetic merged commit 0f62090 into main Apr 25, 2026
41 checks passed
@thetic thetic deleted the cmd-args-consumed branch April 25, 2026 03:24
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.

2 participants