-
Notifications
You must be signed in to change notification settings - Fork 27
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
Handle quoted multi-word argument & option values #21
Comments
Hi tuaris, thanks for reporting. The PHP port of docopt is a pretty straight transliteration of the Python code. It was done this way to make integrating upstream patches easier and to ensure consistency between the implementations. Unfortunately, that means that until the issue is fixed in the Python version, the PHP version will be stuck with this behaviour. I think it makes sense to update the README here to indicate this is a known issue though. I'll keep this issue open so that it's known that this is a problem, but I'll label it as "NeedsUpstreamFix" or somesuch. |
This report is a little misleading. Docopt will only act incorrectly if the input command is provided as a string (docopt then does naïve splitting). If the input is an alread-split array, the bug does not manifest. If you're just using |
Not sure if I'm "doing it wrong", but I am having the same issue as reported in other languages, where Docopt does not treat quote delimited strings as one parameter.
As demonstrated here
Also reported in:
docopt/docopt#207
docopt/try.docopt.org#3
docopt/docopt.R#4
Until this is fixed I suggest putting a warning or removing examples like
git commit
where it's typical for a command likegit commit -m "To have multiple words inside a quote"
.In the mean time I have created a workaround that isn't perfect but has so far worked okay for me. I pre-process and post-process the input/output.
The pre-process function replaces any quoted strings with a variable so that
git commit -m "To have multiple words inside a quote"
becomesgit commit -m $_v12345abcdef
.The
$new_string
is the passed to Docopt handler in place of the normal CLI input args. The result of which is then sent to a post processing function to fill the variables back inFor example, you might have something that looks like this:
I haven't looked through the Docopt.php code, but this might be something that could be done as part of the existing handle() function.
The text was updated successfully, but these errors were encountered: