Refactor command-line arg parsing to use pre-sliced (argc, argv) views#89
Merged
Conversation
Contributor
|
…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
a24b2bb to
5206cc8
Compare
…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.
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.
Description
Replaces the mutable
int& indexthreading through the argument-parsing chain with explicit return values and pre-sliced argv views. Each helper now receives(int argc, const char* const* argv)whereargv[0]is always the flag under inspection, eliminating position arithmetic inside helpers.JUnitOutputPluginretains its original default package name (binary basename) by accepting it as a constructor parameter populated byCommandLineRunner.Related Issues
Fixes # (issue number)
Type of Change
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:
Checklist
docs/for any user-facing changes.mu::tinynamespace,INCLUDED_MU_TINY_guards,mutiny_C-prefix)..hand.c.cpp) is required for parity.CONTRIBUTING.mdfile to ensure compliance with architectural guidelines.