Description
Using docopt for building utilities with relatively wide range of options is pretty limited because of a huge performance penalty.
Namely, a combinatorial explosion may happen in the transform function: the pattern expansion (like ((-a | -b) (-c | -d)) => (-a -c | -a -d | -b -c | -b -d)) has unacceptable computational complexity.
A good example would be the GNU ls utility. See the sample below.
To Reproduce
The script below takes almost 3 seconds to run which is terribly slow for just to parse CLI arguments.
"""
ls with a subset of GNU options (that's not even all of them!)
Usage:
ls [-a|-A] [--hide=PATTERN] [-I=PATTERN] [-dLR]
[--color] [-h|--si] [--indicator-style=WORD|-p|-F|--file-type]
[--format=WORD|-x|-m|-x|-l|-1|-C|-g|-n|-o] [-Giks]
[--sort=WORD|-f|-U|-S|-t|-v|-X] [--group-directories-first] [-r]
[--time=WORD|-u|-c] [--time-style=TIME_STYLE]
[FILES ...]
ls --help
ls --version
Arguments:
FILES
list of files
"""
from docopt import docopt
args = docopt()
Description
Using
docoptfor building utilities with relatively wide range of options is pretty limited because of a huge performance penalty.Namely, a combinatorial explosion may happen in the
transformfunction: the pattern expansion (like((-a | -b) (-c | -d)) => (-a -c | -a -d | -b -c | -b -d)) has unacceptable computational complexity.A good example would be the GNU
lsutility. See the sample below.To Reproduce
The script below takes almost 3 seconds to run which is terribly slow for just to parse CLI arguments.