From ca547beea76ee9458703e1a052e91effd034ee2a Mon Sep 17 00:00:00 2001 From: Martin Craig <martin.craig@eng.ox.ac.uk> Date: Tue, 10 Jul 2018 10:19:34 +0100 Subject: [PATCH] Add singlechar_args option to applyArgStyle for standard handling of single-char arguments If specified, single-character arguments always take single dash prefix even if argument style is --. This is a standard variation. --- fsl/wrappers/wrapperutils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py index cfeed50ff..1ad76869a 100644 --- a/fsl/wrappers/wrapperutils.py +++ b/fsl/wrappers/wrapperutils.py @@ -181,7 +181,7 @@ generated command line arguments. """ -def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs): +def applyArgStyle(style, valsep=None, argmap=None, valmap=None, singlechar_args=False, **kwargs): """Turns the given ``kwargs`` into command line options. This function is intended to be used to automatically generate command line options from arguments passed into a Python function. @@ -240,6 +240,9 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs): The argument for any options not specified in the ``valmap`` will be converted into strings. + :arg singlechar_args: If True, single character arguments always take a single + hyphen prefix (e.g. -h) regardless of the style + :arg kwargs: Arguments to be converted into command-line options. :returns: A list containing the generated command-line options. @@ -265,7 +268,7 @@ def applyArgStyle(style, valsep=None, argmap=None, valmap=None, **kwargs): if valmap is None: valmap = {} def fmtarg(arg): - if style in ('-', '-='): arg = '-{}'.format(arg) + if style in ('-', '-=') or (singlechar_args and len(arg) == 1): arg = '-{}'.format(arg) elif style in ('--', '--='): arg = '--{}'.format(arg) return arg -- GitLab