Skip to content

Commit 93b08af

Browse files
committed
Support using methods as commands
This merely involves skipping the first argument when creating a command from a method.
1 parent 3448ca9 commit 93b08af

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

flask_script/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ def command(self, func):
265265
"""
266266

267267
args, varargs, keywords, defaults = inspect.getargspec(func)
268+
if inspect.ismethod(func):
269+
args = args[1:]
268270

269271
options = []
270272

tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ def hello(name):
263263
out, err = capsys.readouterr()
264264
assert 'hello joe' in out
265265

266+
def test_method_command_decorator_with_pos_arg(self, capsys):
267+
268+
manager = Manager(self.app)
269+
270+
class SomeTest(object):
271+
def hello(self,name):
272+
print('hello ' + name)
273+
sometest = SomeTest()
274+
manager.command(sometest.hello)
275+
276+
assert 'hello' in manager._commands
277+
278+
code = run('manage.py hello joe', lambda: manager.run())
279+
out, err = capsys.readouterr()
280+
assert 'hello joe' in out
281+
266282
def test_command_decorator_with_options(self, capsys):
267283

268284
manager = Manager(self.app)

0 commit comments

Comments
 (0)