Skip to content

Commit

Permalink
Merge pull request #4939 from MCGallaspy/4935-arg-parse-bug
Browse files Browse the repository at this point in the history
Allow positional arguments with dashes inside
  • Loading branch information
rtibbles committed Mar 1, 2016
2 parents 081deee + b5ca734 commit 1d79c20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ If not all TODOs are marked, this PR is considered WIP (work in progress)
- [ ] Have **tests** been written for the new code? If you're fixing a bug, write a regression test (or have a really good reason for not writing one... and I mean **really** good!)
- [ ] Has documentation been written/updated?
- [ ] New dependencies (if any) added to requirements file
- [ ] Add an entry to CHANGELOG.rst

## Reviewer guidance

Expand Down
14 changes: 11 additions & 3 deletions kalitectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@
import cherrypy

# We do not understand --option value, only --option=value.
# Match all patterns of "--option value" and fail if they exist
__validate_cmd_options = re.compile(r"--?[^\s]+\s+(?:(?!--|-[\w]))")
# Similarly, we don't understand -o Foo, only -oFoo
# Match all patterns as above and fail if they exist
# With single-dash options, there's a corner case if a dash appears in a positional argument, like so:
# kalite manage retrievecontentpack local es-ES foo.zip
# Be sure to match whitespace *before* the option starts, so that dashes *inside* arguments are okay!
# (?!...) is a negative lookahead assertion. It only matches if the ... pattern *isn't* found!
__validate_cmd_options = re.compile(r"\s--?[^\s]+\s+(?!--|-[\w])")
if __validate_cmd_options.search(" ".join(sys.argv[1:])):
sys.stderr.write("Please only use --option=value or -x123 patterns. No spaces allowed between option and value. The option parser gets confused if you do otherwise.\n\nWill be fixed in a future release.")
sys.stderr.write("Please only use --option=value or -x123 patterns. No spaces allowed between option and value. "
"The option parser gets confused if you do otherwise."
"\nAdditionally, please put all Django management command options *after* positional arguments."
"\n\nWill be fixed in a future release.")
sys.exit(1)

from threading import Thread
Expand Down

0 comments on commit 1d79c20

Please sign in to comment.