Merge pull request #46197 from terminalmage/split-input-map

Add mapper to salt.utils.args.split_input()
This commit is contained in:
Nicole Thomas 2018-03-02 16:48:17 -05:00 committed by GitHub
commit 218c2af39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ import shlex
# Import salt libs
from salt.exceptions import SaltInvocationError
from salt.ext import six
from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-builtin
from salt.ext.six.moves import map, zip # pylint: disable=import-error,redefined-builtin
import salt.utils.data
import salt.utils.jid
import salt.utils.versions
@ -339,16 +339,18 @@ def argspec_report(functions, module=''):
return ret
def split_input(val):
def split_input(val, mapper=None):
'''
Take an input value and split it into a list, returning the resulting list
'''
if mapper is None:
mapper = lambda x: x
if isinstance(val, list):
return val
return list(map(mapper, val))
try:
return [x.strip() for x in val.split(',')]
return list(map(mapper, [x.strip() for x in val.split(',')]))
except AttributeError:
return [x.strip() for x in six.text_type(val).split(',')]
return list(map(mapper, [x.strip() for x in six.text_type(val).split(',')]))
def test_mode(**kwargs):