CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?

Cameron Simpson cs at cskk.id.au
Thu Oct 15 19:20:40 EDT 2020


On 16Oct2020 10:09, Samuel Marks <samuelmarks at gmail.com> wrote:
>Yes it’s my module, and I’ve been using argparse
>https://github.com/SamuelMarks/ml-params
>
>No library I’ve found provides a solution to CLI argument parsing for my
>use-case.
>
>So I’ll write one. But what should it look like, syntactically and
>semantically?

I would make it look like argparse, if you're using argparse already. 
Can argparse be subclassed, eg to override some internal 
option-gathering method?

In particular, I would not invent yet another command line syntax.

I'd stick with the common -a and --long-name style, maybe using the -{ -} 
stuff you cited from nginx if it meets your needs. As with any 
bracketing syntax, you may one day find yourself needing to embed the 
literal end-bracket symbol in your command line one day, and thus may 
need some kind of escaping notion ("no! not closing the brackets yet!").

I can't offer mch specific advice on argparse, I use getopt myself.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list