Skip to content

Instantly share code, notes, and snippets.

@wjwwood
Created September 3, 2014 21:11
Show Gist options
  • Select an option

  • Save wjwwood/ca8264e8ffdc8b502224 to your computer and use it in GitHub Desktop.

Select an option

Save wjwwood/ca8264e8ffdc8b502224 to your computer and use it in GitHub Desktop.
argument function
def extract_argument_group(args, delimiting_option):
"""Extract a group of arguments from a list of arguments using a delimeter.
Here is an example:
.. code-block:: python
>>> extract_argument_group(['foo', '--args', 'bar', '--baz'], '--args')
(['foo'], ['bar', '--baz'])
The group can always be endded using the double hyphen ``--``.
In order to pass a double hyphen as arguments, use three hyphens ``---``.
Any set of hypens encountered after the delimeter, and up to ``--``, which
have three or more hyphens and are isolated, will be captured and reduced
by one hyphen.
For example:
.. code-block:: python
>> extract_argument_group(['foo',
'--args', 'bar', '--baz', '---', '--',
'--foo-option'], '--args')
(['foo', '--foo-option'], ['bar', '--baz', '--'])
In the result the ``--`` comes from the ``---`` in the input.
The ``--args`` and the corresponding ``--`` are removed entirely.
:param list args: list of strings which are ordered arguments.
:param str delimiting_option: option which denotes where to split the args.
:returns: tuple of arguments before and after the delimeter.
:rtype: tuple
"""
pass # ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment