Skip to content

argparse: make whether or not an option is required dependent on the value of another option #114411

@mulkieran

Description

@mulkieran

Feature or enhancement

Proposal:

Suppose we have one option, --do, and it is restricted to a set of choices, e.g., job1, job2.

Suppose we have another option, --how, and it is only meaningful if --do=job1 is selected.

It would be nice if the required entry for the --how option, instead of just receiving the values True or False would permit some way of indicating "if --how is job1".

If the --do option were a required positional argument, then it would be fairly easy to handle it via a subcommand. But if it is, itself, optional, then that would not work.

This would be even nicer if it would be possible to make a group required or not required depending on the value of some other option and would work very well with the proposed mutually inclusive groups: #55797 enhancement.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement
    No fields configured for issues without a type.

    Projects

    Status
    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions