Permalink
Browse files

Only pass argument if a command's accepts it. Workaround for #71

  • Loading branch information...
1 parent bb68734 commit 00ca89a5dddb45a035b31e8224491a50f8ba33c4 @techniq techniq committed Dec 5, 2013
Showing with 9 additions and 1 deletion.
  1. +9 −1 flask_script/__init__.py
View
@@ -5,6 +5,7 @@
import re
import sys
import inspect
+import warnings
import argparse
@@ -161,7 +162,14 @@ def create_parser(self, prog, parents=None):
usage = getattr(command, 'usage', None)
help = getattr(command, 'help', command.__doc__)
description = getattr(command, 'description', command.__doc__)
- command_parser = command.create_parser(name, parents=[options_parser])
+
+ # Only pass `parents` argument for commands that support it
+ if 'parents' in inspect.getargspec(command.create_parser).args:
+ command_parser = command.create_parser(name, parents=[options_parser])
+ else:
+ warnings.warn("create_parser for {0} command should accept a `parents` argument".format(name))
+ command_parser = command.create_parser(name)
+
subparser = subparsers.add_parser(name, usage=usage, help=help,
description=description,
parents=[command_parser], add_help=False)

0 comments on commit 00ca89a

Please sign in to comment.