Python argparse: Display parse_known_args mode in usage string
argparse, python
Solution
I think you could do this with a combination of `format_usage()` and the ArgumentParser attribute `usage`. Note that that section shows usage as a keyword argument to the constructor, however, inspecting the source for `usage` shows that you can access it after construction as `parser.usage`.
I imagine your final solution would look something like:
parser = argparse.ArgumentParser()
# Add arguments...
usage = parser.format_usage()
parser.usage = usage.rstrip() + ' ...\n'
Problem
When using Python's argparse module you can use `parse_known_args()` to parse only arguments that are known to the parser and any additional arguments are returned separately. However, this fact is not denoted in the usage/help string. Of course I could put it in the `description` field of the parser, but I wonder if there's a nice way to include it in the usage line. What I'm looking for is an output of e.g. `usage: test [-h] ...` instead of `usage: test [-h]`