I have a use case where users provide a docopt string, and based on it, I generate some code. So I do not know my docopt string up front.
For certain "argument types" (not datatypes), I wish to generate various code.
In the following, I will distinguish between "types" and "datatypes". For the docopt argument --arg=DEGREES
and the argv input --arg=10
, the "type" of --arg
is DEGREES
, while the datatype is integer
. The value is 10
.
A user may give me the following docopt string:
Naval Fate.
Usage:
naval_fate --dir=FILE [--speed=ABC]
Options:
--dir=FILE Moored (anchored) mine.
--speed=ABC Speed in knots [default: 10].
Besides parsing this docopt string as usual, I'm trying to also figure out what "type" of argument dir
and speed
asks for. I want to know that dir
is of type FILE
and speed
is of type ABC
.
Example:
Given the above docopt string, and an argv string naval_fate --dir=/tmp --speed 1234
, I hope to access not just the value and datatype (<key> => <value,datatype>
), but also the "config type" (<key> => <value,datatype,argtype>
, i.e. something along the lines of:
dir
=> val: /tmp
, datatype: String
, type: FILE
speed
=> val: 1234
, datatype: Integer
, type: ABC
Any (managed) implementation of docopt is acceptable, including Python's, though preferably I'm looking for a solution in a compiled language, be it C, Go, Rust etc.