Skip to content

Refactor _build_cli_args to table-driven CLI flag mapping #6

Description

@dustinblack

Summary

_build_cli_args in rusty_comms_plugin.py uses a long chain of explicit if statements to map TestRunConfig fields to CLI flags. This works but becomes harder to maintain as new flags are added — each new field requires a new conditional block with its own formatting logic.

Suggestion

Replace the if-chain with a table-driven approach — e.g. a list of (field_name, flag, transform) tuples iterated in a loop:

FLAG_MAP = [
    ("message_size", "-s", str),
    ("msg_count", "-i", str),
    ("duration", "-d", None),
    ("concurrency", "-c", str),
    ("buffer_size", "--buffer-size", str),
    ...
]

for field, flag, transform in FLAG_MAP:
    value = getattr(params, field, None)
    if value is not None:
        args.extend([flag, transform(value) if transform else value])

Boolean flags and special cases (like percentiles with repeated --percentiles args, or mechanisms which uses positional args) would need separate handling, but the bulk of the simple value flags could collapse into the loop.

Benefits

  • Adding a new CLI flag becomes a one-line table entry instead of a new if-block
  • Reduces risk of inconsistencies in flag formatting
  • Easier to audit the full set of supported flags at a glance

Notes

Not urgent — the current implementation is correct and readable. This is a maintainability improvement for when the next batch of flags is added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions