Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclusive arguments not allowed in CLI #2769

Closed
Sjord opened this issue Jan 21, 2024 · 0 comments · Fixed by #2770
Closed

Exclusive arguments not allowed in CLI #2769

Sjord opened this issue Jan 21, 2024 · 0 comments · Fixed by #2770

Comments

@Sjord
Copy link
Contributor

Sjord commented Jan 21, 2024

In gitlab/v4/cli.py, required and optional arguments are added to the argument parser:

if action_name == "create":
    for x in mgr_cls._create_attrs.required:
        sub_parser_action.add_argument(
            f"--{x.replace('_', '-')}", required=True
        )
    for x in mgr_cls._create_attrs.optional:
        sub_parser_action.add_argument(
            f"--{x.replace('_', '-')}", required=False
        )

Besides required and optional, the RequiredOptional class can also have an exclusive field, and many objects use this to list options not in required or optional. From gitlab/v4/objects/invitations.py:

class ProjectInvitationManager(InvitationMixin, RESTManager):
    _path = "/projects/{project_id}/invitations"
    _obj_cls = ProjectInvitation
    _from_parent_attrs = {"project_id": "id"}
    _create_attrs = RequiredOptional(
        required=("access_level",),
        optional=(
            "expires_at",
            "invite_source",
            "tasks_to_be_done",
            "tasks_project_id",
        ),
        exclusive=("email", "user_id"),
    )

Here email is an argument defined in exclusive, and not allowed on the CLI:

$ python -m gitlab --server-url http://172.16.38.146/ project-invitation create --access-level 10 --email myemail --project-id 1
...
__main__.py: error: unrecognized arguments: --email myemail

Issue #2738 describes a similar problem.

Sjord added a commit to Sjord/python-gitlab that referenced this issue Jan 21, 2024
The CLI takes its arguments from the RequiredOptional, which has three fields: required, optional, and exclusive. In practice, the exclusive options are not defined as either required or optional, and would not be allowed in the CLI. This changes that, so that exclusive options are also added to the argument parser.

Closes python-gitlab#2769
Sjord added a commit to Sjord/python-gitlab that referenced this issue Jan 21, 2024
The CLI takes its arguments from the RequiredOptional, which has three fields: required, optional, and exclusive. In practice, the exclusive options are not defined as either required or optional, and would not be allowed in the CLI. This changes that, so that exclusive options are also added to the argument parser.

Closes python-gitlab#2769
JohnVillalovos pushed a commit to Sjord/python-gitlab that referenced this issue Jan 28, 2024
The CLI takes its arguments from the RequiredOptional, which has three fields: required, optional, and exclusive. In practice, the exclusive options are not defined as either required or optional, and would not be allowed in the CLI. This changes that, so that exclusive options are also added to the argument parser.

Closes python-gitlab#2769
JohnVillalovos pushed a commit to Sjord/python-gitlab that referenced this issue Jan 29, 2024
The CLI takes its arguments from the RequiredOptional, which has three fields: required, optional, and exclusive. In practice, the exclusive options are not defined as either required or optional, and would not be allowed in the CLI. This changes that, so that exclusive options are also added to the argument parser.

Closes python-gitlab#2769
JohnVillalovos pushed a commit that referenced this issue Jan 29, 2024
* fix(cli): allow exclusive arguments as optional

The CLI takes its arguments from the RequiredOptional, which has three fields: required, optional, and exclusive. In practice, the exclusive options are not defined as either required or optional, and would not be allowed in the CLI. This changes that, so that exclusive options are also added to the argument parser.

  * fix(cli): inform argument parser that options are mutually exclusive

  * fix(cli): use correct exclusive options, add unit test

Closes #2769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant