Debian Codegraph @

test/lib/ansible_test/_internal/cli/converters.py

raw
1 """Converters for use as the type argument for arparse's add_argument method."""
2
3 from __future__ import annotations
4
5 import argparse
6
7
8 def key_value_type(value: str) -> tuple[str, str]:
9 """Wrapper around key_value."""
10 return key_value(value)
11
12
13 def key_value(value: str) -> tuple[str, str]:
14 """Type parsing and validation for argparse key/value pairs separated by an '=' character."""
15 parts = value.split('=')
16
17 if len(parts) != 2:
18 raise argparse.ArgumentTypeError('"%s" must be in the format "key=value"' % value)
19
20 return parts[0], parts[1]