The adb shell am
command (activity manager) has parameters like this:
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
To my knowledge argparse
is the python way to parse arguments. I'd need an action that should:
- consists of 2 or more arguments (eg.
--eia key1 1 2 3
) (see last point) - is optional
- edit it can occour multiple times, eg.
--eia key1 1,2 --eia key2 2,1
is valid - the type of the first argument may differ from the type of the rest
- other optional arguments like this can exist
- the example has the delimiter of a
,
but I'd like to allow delimiting with spaces, because my actual argument values may be strings and I'd like to leave parsing them to the shell (if a string should start with-
, quotation marks help:"-asdf"
)
An other question has an answer that can do this with positional arguments:
parser = argparse.ArgumentParser(usage='%(prog)s [-h] file file [file ...]')
parser.add_argument('file1', nargs=1, metavar='file')
parser.add_argument('file2', nargs='+', metavar='file', help=argparse.SUPPRESS)
namespace = parser.parse_args()
namespace.file = namespace.file1 + namespace.file2
But I cannot see if these works for optional arguments too?
With my requirements is it a good idea to start with argparse
at all? Are there other options?