MCPcopy Index your code
hub / github.com/aws/aws-cli / validate_mutually_exclusive

Function validate_mutually_exclusive

awscli/customizations/utils.py:99–120  ·  view source on GitHub ↗

Validate mutually exclusive groups in the parsed args.

(parsed_args, *groups)

Source from the content-addressed store, hash-verified

97
98
99def validate_mutually_exclusive(parsed_args, *groups):
100 """Validate mutually exclusive groups in the parsed args."""
101 args_dict = vars(parsed_args)
102 all_args = set(arg for group in groups for arg in group)
103 if not any(k in all_args for k in args_dict if args_dict[k] is not None):
104 # If none of the specified args are in a mutually exclusive group
105 # there is nothing left to validate.
106 return
107 current_group = None
108 for key in [k for k in args_dict if args_dict[k] is not None]:
109 key_group = _get_group_for_key(key, groups)
110 if key_group is None:
111 # If they key is not part of a mutex group, we can move on.
112 continue
113 if current_group is None:
114 current_group = key_group
115 elif not key_group == current_group:
116 raise ParamValidationError(
117 'The key "%s" cannot be specified when one '
118 'of the following keys are also specified: '
119 '%s' % (key, ', '.join(current_group))
120 )
121
122
123def _get_group_for_key(key, groups):

Callers 4

_run_mainMethod · 0.90
_handlerFunction · 0.85

Calls 2

_get_group_for_keyFunction · 0.85

Tested by

no test coverage detected