keleshev / docopt.ml

Work in progress…
https://pubs.opengroup.org/onlinepubs/9699919799/
3 stars 0 forks source link

Default value quoting/whitespace #1

Open NickCrews opened 2 months ago

NickCrews commented 2 months ago

For your interest, a poorly-defined corner of the current docopt spec is quoting and whitespace for default values: https://github.com/jazzband/docopt-ng/issues/46

If you continue working on this, you may want to consider this and define expected behavior.

keleshev commented 1 month ago

Thanks for raising this issue. I plan to implement a subset of shell parser to handle single "words", single-quoted strings and doubly-quoted strings according to POSIX shell lexical conventions:

(default: hello)
(default: 'hello')
(default: "hello")

One thing it allows is to naturally handle environment variables. You can say:

(default: $HOME)
(default: "$HOME")
(default: "${HOME}")
(default: "${USER} @ {HOST}") # even more vars!

And use escaping and single quotes if you really need the dollar sign:

(default: \$100)
(default: '$100')
(default: "\$100")

The one questions on my mind is what to do if only some envars are not defined: return null for the whole parameter, or interpolate it as an empty string. For example:

Usage: prog [--foo=<foo>]

Options:
  --foo=<foo>  (default: "$BAZ @ $BAR")
$ BAZ=1 BAR=2 prog # => {"--foo": "1 @ 2"}
$ prog --foo=3     # => {"--foo": "3"}
$ BAZ=1 prog       # => {"--foo": ???}   null or "1 @ "

Probably the rule should be: if any envar from the default is not defined, the default is null.