osrf_pycommon.cli_utils.common module
Commonly used, CLI related functions.
- osrf_pycommon.cli_utils.common.extract_argument_group(args, delimiting_option)
Extract a group of arguments from a list of arguments using a delimiter.
Here is an example:
>>> extract_argument_group(['foo', '--args', 'bar', '--baz'], '--args') (['foo'], ['bar', '--baz'])
The group can always be ended using the double hyphen
--
. In order to pass a double hyphen as arguments, use three hyphens---
. Any set of hyphens encountered after the delimiter, and up to--
, which have three or more hyphens and are isolated, will be captured and reduced by one hyphen.For example:
>> 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.The delimiter and
--
terminator combination can also happen multiple times, in which case the bodies of arguments are combined and returned in the order they appeared.For example:
>> extract_argument_group(['foo', '--args', 'ping', '--', 'bar', '--args', 'pong', '--', 'baz', '--args', '--'], '--args') (['foo', 'bar', 'baz'], ['ping', 'pong'])
Note:
--
cannot be used as thedelimiting_option
.- Parameters:
args (list) – list of strings which are ordered arguments.
delimiting_option (str) – option which denotes where to split the args.
- Returns:
tuple of arguments before and after the delimiter.
- Return type:
tuple
- Raises:
ValueError if the delimiting_option is
--
.
- osrf_pycommon.cli_utils.common.extract_jobs_flags(arguments)
Extracts make job flags from a list of other make flags, i.e. -j8 -l8
The input arguments are given as a string separated by whitespace. Make job flags are matched and removed from the arguments, and the Make job flags and what is left over from the input arguments are returned.
If no job flags are encountered, then an empty string is returned as the first element of the returned tuple.
Examples:
>> extract_jobs_flags('-j8 -l8') ('-j8 -l8', '') >> extract_jobs_flags('-j8 ') ('-j8', ' ') >> extract_jobs_flags('target -j8 -l8 --some-option') ('-j8 -l8', 'target --some-option') >> extract_jobs_flags('target --some-option') ('', 'target --some-option')
- Parameters:
arguments (str) – string of space separated arguments which may or may not contain make job flags
- Returns:
tuple of make jobs flags as a space separated string and leftover arguments as a space separated string
- Return type:
tuple