Skip to content

Commit

Permalink
feat(args): print error if one of --user-id or --group-id is set and …
Browse files Browse the repository at this point in the history
…other isn't
  • Loading branch information
actionless committed Jan 14, 2025
1 parent 0f4d19d commit 5ed3833
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pikaur/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,22 @@ def get_pikaur_int_opts(action: str | None = None) -> ArgSchema:
for each_action in ALL_ACTIONS:
result += get_pikaur_int_opts(each_action)
return list(set(result))
result += [
Arg(
None, "user-id", PikaurConfig().misc.UserId.get_int(),
translate("user ID to run makepkg if pikaur started from root"),
),
Arg(
None, "group-id", PikaurConfig().misc.GroupId.get_int(),
translate("group ID to run makepkg if pikaur started from root"),
),
]
if action in {"sync", "pkgbuild", "interactive_package_select"}:
result += [
Arg(
None, "aur-clone-concurrency", None,
translate("how many git-clones/pulls to do from AUR"),
),
Arg(
None, "user-id", PikaurConfig().misc.UserId.get_int(),
translate("user ID to run makepkg if pikaur started from root"),
),
Arg(
None, "group-id", PikaurConfig().misc.GroupId.get_int(),
translate("group ID to run makepkg if pikaur started from root"),
),
]
if action == "extras":
result += [
Expand Down Expand Up @@ -449,10 +451,16 @@ def get_pikaur_count_opts(action: str | None = None) -> ArgSchema:
]


ANY_OPERATION: "Final" = "*"

ARG_DEPENDS: "Final[dict[str, dict[str, list[str]]]]" = {
"query": {
"upgrades": ["aur", "repo"],
},
ANY_OPERATION: {
"user_id": ["group_id"],
"group_id": ["user_id"],
},
}

ARG_CONFLICTS: "Final[dict[str, dict[str, list[str]]]]" = {
Expand Down Expand Up @@ -575,14 +583,14 @@ def post_process_args(self) -> None:

def validate(self) -> None:
for operation, operation_depends in ARG_DEPENDS.items():
if getattr(self, operation):
if getattr(self, operation) or operation == ANY_OPERATION:
for arg_depend_on, dependant_args in operation_depends.items():
if not getattr(self, arg_depend_on):
for arg_name in dependant_args:
if getattr(self, arg_name):
raise MissingArgumentError(arg_depend_on, arg_name)
for operation, operation_conflicts in ARG_CONFLICTS.items():
if getattr(self, operation):
if getattr(self, operation) or operation == ANY_OPERATION:
for args_conflicts, conflicting_args in operation_conflicts.items():
if getattr(self, args_conflicts):
for arg_name in conflicting_args:
Expand Down

0 comments on commit 5ed3833

Please sign in to comment.