Skip to content

refactor snakeoil.arghparse.ParseNonblockingStdin mechanism #121

@ferringb

Description

@ferringb

Argparse flow is first value conversion (validate and convert), then action invocation (store it). ParseNonblockingStdin is an action which is actually a type arg- it converts - into a stream of arguments to inject.

The point is, it moves the parse time validation of each argument item out of the normal argparse flow. My rough thought is it should be this:

scan.add_argument(
    "targets",
    metavar="TARGET",
    nargs="*",
    type=arghparse.ParseNonblockingStdin(actual_value_parser),
    help="if not given, scan the repo.  If given, limit scans to pkgs matching extended atom syntax",
)

Interpose the check for -- if it's that, then expand it out into a sequence, then feed that through the actual validation.

This may have to be done strictly through action if type isn't invoked for the total values, which I'm fairly sure it's not.

Point is: the type conversion should be specifiable directly within the add_argument, and the API of that shim should enable it. The code I've seen using this is using the finalizer system (delayed parsing) which is a beast best not used for things like atom parsing- pkgcheck scan is that example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions