Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value quoting/whitespace #1

Open
NickCrews opened this issue Jul 6, 2024 · 1 comment
Open

Default value quoting/whitespace #1

NickCrews opened this issue Jul 6, 2024 · 1 comment

Comments

@NickCrews
Copy link

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

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

@keleshev
Copy link
Owner

keleshev commented Aug 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants