My command line utility should accept several filters attached to each other (similar to Unix pipeline).
Each filter has a number of options. For example chain
filter currently has the following options:
-t NAMESPACE, --target NAMESPACE
target namespace(s)
-s {precedence,doc}, --next-script {precedence,doc}
"next script" algorithm ("precedence" is not
supported)
-n {ignore,remove,error}, --not-in-target {ignore,remove,error}
what if a result is not in target NS
-u URL, --universal-precedence URL
universal precedence
-W {inverseofsum,sumofinverses}, --weight-formula {inverseofsum,sumofinverses}
formula for weighting scripts
How to represent in command arguments the workflow of filters?
The first thought is to use a JSON array. But JSON is not quite a good format for a command line.
The next thought is to separate the filters with some separator. It may be --
or --separator
or like this. But --
is already taken to separate command line options from other command line arguments, and --separator
does not look good.
Another trouble is that while I use Python 3 argparse
, this package seems not to be well-suited for several subcommands chained in one command line, like:
boiler script filter1 --separator \
chain -t http://www.w3.org/1999/xhtml -n error --separator \
transformation filter2 --arg x=y --separator \
transformation filter3
Here I attempt to chain four filter subcommands: script
, chain
, tranformation
, tranformation
. But Python argparse
(seemingly) does not support having several subcommands in one command line.
So if not argparse
then what library to use to process command lines like this?
My questions:
- What are possible user-friendly formats for such command lines?
- How to parse it with Python
argparse
? - If not
argparse
, then what instead?
Also take note, that in the future I may decide to rewrite my software in some other language (D, probably) than Python.