CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?
Samuel Marks
samuelmarks at gmail.com
Thu Oct 15 05:53:34 EDT 2020
Previously I have solved related problems with explicit `-}` and `-{`
(or `-b`) as in `nginxctl`:
```
$ python -m nginxctl serve --temp_dir '/tmp' \
-b 'server' \
--server_name 'localhost' --listen '8080' \
-b location '/' \
--root '/tmp/wwwroot' \
-} \
-}
nginx is running. Stop with: /usr/local/bin/nginx -c /tmp/nginx.conf -s stop
```
To illustrate the issue, using `ml-params` and ml-params-tensorflow:
```
$ python -m ml_params --engine 'tensorflow' train --help
usage: python -m ml_params train [-h]
--optimizer
{Adadelta,Adagrad,Adam,Adamax,Ftrl,Nadam,RMSprop}
Run the training loop for your ML pipeline.
optional arguments:
-h, --help show this help message and exit
--optimizer {Adadelta,Adagrad,Adam,Adamax,Ftrl,Nadam,RMSprop}
The optimizer
```
Idea: preprocess `sys.argv` so that this syntax would work
`--optimizer Adam[learning_rate=0.01]`*
*square rather than round so as not to require escape characters or
quoting in `sh`
Unfortunately this approach wouldn't give nice `--help` text.
What's the right solution here?
Thanks,
Samuel Marks
Charity <https://sydneyscientific.org> | consultancy
<https://offscale.io> | open-source <https://github.com/offscale> |
LinkedIn <https://linkedin.com/in/samuelmarks>
More information about the Python-list
mailing list