Skip to content

Commit

Permalink
Use shlex to tokenize the input string. Fixes docopt#3
Browse files Browse the repository at this point in the history
Allow the use of quoted arguments, e.g.
```
Usage:
  test <arg1> <arg2>
```
with the input `a "b c d"`

If tokenization fails, fall back to the original behaviour
  • Loading branch information
mikebryant committed May 6, 2016
1 parent d8a5388 commit 2d7704f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--drifting Drifting mine.
"""
import os, sys, traceback, json
import os, sys, traceback, json, shlex
from StringIO import StringIO

from flask import Flask, render_template as render, request
Expand All @@ -27,6 +27,10 @@


def run_docopt(doc, argv):
try:
argv = shlex.split(argv)
except ValueError:
pass
real_stdout, sys.stdout = sys.stdout, StringIO()
real_stderr, sys.stderr = sys.stderr, StringIO()
try:
Expand Down

0 comments on commit 2d7704f

Please sign in to comment.