split_kv¶
- lsst.daf.butler.cli.utils.split_kv(context: ~click.core.Context, param: ~click.core.Option, values: list[str], *, choice: ~click.types.Choice | None = None, multiple: bool = True, normalize: bool = False, separator: str = '=', unseparated_okay: bool = False, return_type: type[dict] | type[tuple] = <class 'dict'>, default_key: str | None = '', reverse_kv: bool = False, add_to_default: bool = False) dict[str | None, str] | tuple[tuple[str | None, str], ...]¶
- Process a tuple of values that are key-value pairs separated by a given separator. Multiple pairs may be comma separated. Return a dictionary of all the passed-in values. - This function can be passed to the ‘callback’ argument of a click.option to allow it to process comma-separated values (e.g. “–my-opt a=1,b=2”). - Parameters:
- contextclick.ContextorNone
- The current execution context. Unused, but Click always passes it to callbacks. 
- paramclick.core.OptionorNone
- The parameter being handled. Unused, but Click always passes it to callbacks. 
- values[str]
- All the values passed for this option. Strings may contain commas, which will be treated as delimiters for separate values. 
- choiceclick.Choice, optional
- If provided, verify each value is a valid choice using the provided - click.Choiceinstance. If None, no verification will be done. By default- None.
- multiplebool, optional
- If true, the value may contain multiple comma-separated values. By default True. 
- normalizebool, optional
- If True and - choice.case_sensitive == False, normalize the string the user provided to match the choice’s case. By default- False.
- separatorstr, optional
- The character that separates key-value pairs. May not be a comma or an empty space (for space separators use Click’s default implementation for tuples; - type=(str, str)). By default “=”.
- unseparated_okaybool, optional
- If True, allow values that do not have a separator. They will be returned in the values dict as a tuple of values in the key ‘’, that is: - values[''] = (unseparated_values, ). By default False.
- return_typetype, must bedictortuple
- The type of the value that should be returned. If - dictthen the returned object will be a dict, for each item in values, the value to the left of the separator will be the key and the value to the right of the separator will be the value. If- tuplethen the returned object will be a tuple. Each item in the tuple will be 2-item tuple, the first item will be the value to the left of the separator and the second item will be the value to the right. By default- dict.
- default_keystrorNone
- The key to use if a value is passed that is not a key-value pair. - Nonecan imply no separator depending on how the results are handled. (Passing values that are not key-value pairs requires- unseparated_okayto be- True).
- reverse_kvbool
- If true then for each item in values, the value to the left of the separator is treated as the value and the value to the right of the separator is treated as the key. By default - False.
- add_to_defaultbool, optional
- If True, then passed-in values will not overwrite the default value unless the - return_typeis- dictand passed-in value(s) have the same key(s) as the default value.
 
- context
- Returns:
- Raises:
- click.ClickException
- Raised if the separator is not found in an entry, or if duplicate keys are encountered.