Skip to content

Make arg_parse output transactional on parse failure #145

Description

@codeforester

Problem

arg_parse clears and mutates caller-owned output arrays while it parses. If parsing fails after some earlier options were accepted, the caller can observe partially mutated state even though the function returned usage status 2.

A local repro from the review pass showed an existing option map being cleared and verbose=1 being written before a later --unknown option failed.

Fix

Parse into local temporary arrays first, and only publish to the caller-owned options and positionals arrays after the entire parse succeeds. Add regression coverage for both unknown-option and missing-value failures.

Validation

  • Focused lib/bash/arg/tests/lib_arg.bats coverage
  • ./tests/validate.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions