Permalink
Browse files

Merge pull request #79 from clee704/master

Separate usage into usage/help/description
  • Loading branch information...
2 parents e7a48b0 + b3e2536 commit 62c41765ce04b254169b15d80acb2d2950d004c6 @techniq techniq committed Nov 7, 2013
Showing with 31 additions and 7 deletions.
  1. +9 −3 flask_script/__init__.py
  2. +2 −2 flask_script/commands.py
  3. +20 −2 tests.py
View
@@ -65,7 +65,7 @@ def run(self):
"""
def __init__(self, app=None, with_default_commands=None, usage=None,
- disable_argcomplete=False):
+ help=None, description=None, disable_argcomplete=False):
self.app = app
@@ -77,7 +77,9 @@ def __init__(self, app=None, with_default_commands=None, usage=None,
if with_default_commands or (app and with_default_commands is None):
self.add_default_commands()
- self.usage = self.description = usage
+ self.usage = usage
+ self.help = help if help is not None else usage
+ self.description = description if description is not None else usage
self.disable_argcomplete = disable_argcomplete
self.parent = None
@@ -150,14 +152,18 @@ def create_parser(self, prog, parents=None):
# parser_parents = [options_parser]
parser = argparse.ArgumentParser(prog=prog, usage=self.usage,
+ description=self.description,
parents=[options_parser])
subparsers = parser.add_subparsers()
for name, command in self._commands.items():
+ 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])
- subparser = subparsers.add_parser(name, usage=description, help=description,
+ subparser = subparsers.add_parser(name, usage=usage, help=help,
+ description=description,
parents=[command_parser], add_help=False)
View
@@ -197,7 +197,7 @@ class Shell(Command):
banner = ''
- description = 'Runs a Python shell inside Flask application context.'
+ help = description = 'Runs a Python shell inside Flask application context.'
def __init__(self, banner=None, make_context=None, use_ipython=True,
use_bpython=True):
@@ -286,7 +286,7 @@ class Server(Command):
:param options: :func:`werkzeug.run_simple` options.
"""
- description = 'Runs the Flask development server i.e. app.run()'
+ help = description = 'Runs the Flask development server i.e. app.run()'
def __init__(self, host='127.0.0.1', port=5000, use_debugger=True,
use_reloader=True, threaded=False, processes=1,
View
@@ -714,14 +714,23 @@ def test_manager_usage_with_submanager(self, capsys):
assert code == 0
assert 'Example sub-manager' in out
- def test_submanager_usage(self, capsys):
+ def test_submanager_usage_and_help_and_description(self, capsys):
- sub_manager = Manager(usage='Example sub-manager')
+ sub_manager = Manager(usage='sub_manager [--foo]',
+ help='shorter desc for submanager',
+ description='longer desc for submanager')
sub_manager.add_command('simple', SimpleCommand())
manager = Manager(self.app)
manager.add_command('sub_manager', sub_manager)
+ code = run('manage.py -h', lambda: manager.run())
+ out, err = capsys.readouterr()
+ assert code == 0
+ assert 'sub_manager [--foo]' not in out
+ assert 'shorter desc for submanager' in out
+ assert 'longer desc for submanager' not in out
+
code = run('manage.py sub_manager', lambda: manager.run())
out, err = capsys.readouterr()
assert code == 2
@@ -730,6 +739,15 @@ def test_submanager_usage(self, capsys):
code = run('manage.py sub_manager -h', lambda: manager.run())
out, err = capsys.readouterr()
assert code == 0
+ assert 'sub_manager [--foo]' in out
+ assert 'shorter desc for submanager' not in out
+ assert 'longer desc for submanager' in out
+ assert 'simple command' in out
+
+ code = run('manage.py sub_manager simple -h', lambda: manager.run())
+ out, err = capsys.readouterr()
+ assert code == 0
+ assert 'sub_manager [--foo] simple [-h]' in out
assert 'simple command' in out
def test_submanager_has_no_default_commands(self):

0 comments on commit 62c4176

Please sign in to comment.